递归方式遍历目录及目录下的文件

';
    
    $source = opendir($path);

    while ($fileName = readdir($source)) {
        if ($fileName === '.' || $fileName === '..') continue;

        $dirPath = $path . '/' . $fileName;

        if (is_dir($dirPath)) {
            MyReadDir($dirPath);
        } else {
            echo $dirPath . '
'; } } 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 */

输出

你可能感兴趣的:(递归方式遍历目录及目录下的文件)