這道題也是老題:遍歷文件下的所有目錄和文件
解答:
- <?php
- function showPath($path)
- {
- $handle = opendir($path); //打開傳遞過來的文件
- while($file = readdir($handle)){ //如果讀取文件不爲空
- if($file == "." || $file == "..") continue;
- $newFilePath = $path.DIRECTORY_SEPARATOR.$file;
- if(is_dir($newFilePath)){
- echo "文件夾:".$newFilePath."<br>";
- showPath($newFilePath);
- }
- if(is_file($newFilePath)){
- echo "文件:".$newFilePath;
- }
- closedir($handle);
- }
- }
- showPath('E:') ;
- ?>