Skip to content

Instantly share code, notes, and snippets.

@borislav-angelov
Created May 19, 2014 13:42
Show Gist options
  • Save borislav-angelov/3b3c65fb30d9e2c955c6 to your computer and use it in GitHub Desktop.
Save borislav-angelov/3b3c65fb30d9e2c955c6 to your computer and use it in GitHub Desktop.
readdir
<?php
$dir = "C:\\temp\\";
$start = microtime(true);
function recursive_readdir($dir) {
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if ($filename != '.' && $filename != '..') {
if (is_dir($dir . $filename)) {
recursive_readdir($dir . $filename . '\\');
} else {
//echo $dir . $filename . "\n";
}
}
//echo $filename . "\n";
//$files[] = $filename;
}
closedir($dh);
}
recursive_readdir($dir);
$total = microtime(true) - $start;
echo $total;
echo "\n\n";
$start = microtime(true);
// Use Recursive functions
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
// Skip dots
if ($iterator->isDot()) {
continue;
}
// Add to archive
if ($item->isDir()) {
} else {
//echo $iterator->getSubPathName() . "\n";
}
}
$total = microtime(true) - $start;
echo $total;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment