时间:2021-07-01 10:21:17 帮助过:78人阅读
$handle=opendir("./");
while(false!==($file=readdir($handle))){
if ($file != "." && $file != ".."){
echo "$file
";
}
}
closedir($handle);
?>
public function listDir($path, $size=false, $toCsv=false)
{
if (false !== $toCsv) $newCsv = new SplFileObject($toCsv, 'wb');
$items = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$arr = array();
while (list($itemName, $item) = each($items))
//foreach($dir as $itemName => $item)
{
$fileInfo = array();
$fileInfo['fullpath'] = (string)$itemName;
if ($size) $fileInfo['size'] = (string)$item->getSize();
if (false !== $toCsv) $newCsv->fputcsv($fileInfo);
$arr[] = $fileInfo;
}
return $arr;
}
function show($dir)
{
echo "{$dir}
";
$dir = realpath($dir) .'/*';
foreach(glob($dir, GLOB_MARK) as $f){
if( substr($f, -5) === '.html' ){
$f = "{$f}";
}
echo $f ."
".PHP_EOL;
if(is_dir($f)){
show($f);