<?php $path = "D:/wamp/www/testphp"; $directoryIterator = new RecursiveDirectoryIterator($path); $recursiveIterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST);//第二个常量参数代表在迭代时列出自身 foreach ($recursiveIterator as $file) { /* @var $file SplFileInfo */ echo str_repeat(" ", $recursiveIterator->getDepth()); if ($file->isDir()) { echo DIRECTORY_SEPARATOR; } echo $file->getBasename(); if ($file->isFile()) { echo " (" .$file->getSize(). " bytes)"; } elseif ($file->isLink()) { echo " (symlink)"; } echo'<br/>'; echo PHP_EOL; } ?>