1. 程式人生 > >SPL遍歷資料夾

SPL遍歷資料夾


  

$root = 'D:/www/docroot';

$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
);

$paths = array($root);
foreach ($iter as $path => $dir) {
$paths[] = str_replace("\\", "/", $path);
}

print_r($paths);