Created
May 19, 2014 13:42
-
-
Save borislav-angelov/3b3c65fb30d9e2c955c6 to your computer and use it in GitHub Desktop.
readdir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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