4,250
社区成员
发帖
与我相关
我的任务
分享
$results=array();
$path = "/root";
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $key => $val)
{
$s=pathinfo(trim(str_replace($path,'',$val),'/'));
$x=(!empty($s['dirname'])&&$s['dirname']!='.')?"['".str_replace('/',"']['",$s['dirname'])."']":'';
eval('$results'.$x."[]='".$s['basename']."';");
}
print_R($results);
function showDirectoryFile($path){
$handle = opendir($path);
while($file = readdir($handle)){
if($file=="."||$file=="..") continue;
$newFilePath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($newFilePath)){
echo "文件夹:".$newFilePath."<br>";
showDirectoryFile($newFilePath);
}
if(is_file($newFilePath)) echo "文件:".$newFilePath."<br>";
}
closedir($handle);
}
showDirectoryFile("/usr/local/");
//DIRECTORY_SEPARATOR:路径分隔符,linux上就是’/’ windows上是’\’
//PATH_SEPARATOR:include多个路径使用,在win下,当你要include多个路径的话,你要用”;”隔开,但在linux下就使用”:”隔开的。
function sdir($dir){
$files = scandir($dir);
for ($i=0;$i <count($files);$i++){
if ($files[$i]=='.' or $files[$i]=='..') unset($files[$i]);
if (is_dir($files[$i])) $files[$i]=sdir($files[$i]);
}
return $files;
}
<pre>
<?php
//creator:fxs_2008@sina.com
function get_all_files($path) {
$list = array();
foreach(glob($path . '\*') as $item) {
// 如果是文件
if (is_dir($item)) {
$list[basename($item)] = array_merge($list , get_all_files($item));
} else {
//如果是目录
$list[] = $item;
}
}
return $list;
}
print_r(get_all_files('D:\PHP\www\zzxj\blog'));
?>
</pre>
版权所有啊,引用请注明来源:http://www.zzxj.net/forum