<?php
function MyReadDir($path){
echo $path . '<br>';
$source = opendir($path);
while ($fileName = readdir($source)) {
if ($fileName === '.' || $fileName === '..') continue;
$dirPath = $path . '/' . $fileName;
if (is_dir($dirPath)) {
MyReadDir($dirPath);
} else {
echo $dirPath . '<br/>';
}
}
closedir($source);
}
MyReadDir('./c');
//tree
/*
[root@localhost html]# tree dir/
dir/
└── c
├── App
├── User
│ └── kevin
│ ├── a.txt
│ └── b
│ └── b.txt
└── Windows
└── System32
└── host.txt
*/
//输出
/*
./c
./c/User
./c/User/kevin
./c/User/kevin/a.txt
./c/User/kevin/b
./c/User/kevin/b/b.txt
./c/Windows
./c/Windows/System32
./c/Windows/System32/host.txt
./c/App
*/
输出