php获取当前目录下文件夹列表
获取当前目录下文件夹的名称
应用案例
$url="D:/wwwroot/ytecn.com/ui/"; $list=GetDirsInDir($url); print_r($list);
输出结果为:
Array ( [0] => code [1] => css [2] => img [3] => js [4] => tinymce )
函数
function GetDirsInDir($dir) { $dirs = array(); if (!file_exists($dir)) { return array(); } if (!is_dir($dir)) { return array(); } $dir = str_replace('\\', '/', $dir); if (substr($dir, -1) !== '/') { $dir .= '/'; } if (function_exists('scandir')) { foreach (scandir($dir, 0) as $d) { if (is_dir($dir . $d)) { if (($d != '.') && ($d != '..')) { $dirs[] = $d; } } } } else { $handle = opendir($dir); if ($handle) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir($dir . $file)) { $dirs[] = $file; } } } closedir($handle); } } return $dirs; }