<?php |
/* |
* 获取指定目录下的文件和文件夹,并将文件和文件夹分别以逗号间隔输出。 |
*/ |
function getAllFilesAndDirs( $path ){ |
$files = '' ; |
$dirs = '' ; |
$alls = scandir( $path ); |
if (! empty ( $alls )){ |
foreach ( $alls as $all ){ |
if ( $all != "." && $all != ".." ){ |
if ( is_file ( $path . '/' . $all )){ |
if ( empty ( $files )){ |
$files .= $all ; |
} else { |
$files .= "," . $all ; |
} |
} |
if ( is_dir ( $path . '/' . $all )){ |
if ( empty ( $dirs )){ |
$dirs .= $all ; |
} else { |
$dirs .= "," . $all ; |
} |
} |
} |
} |
} else { |
echo "input param is not a valid path." ; |
} |
return "dirs: " . $dirs . " files: " . $files ; |
} |
//获取当前文件夹下的cleanAD中的文件和文件夹。 |
echo getAllFilesAndDirs( "cleanAD" ); |
?> |