Created
February 20, 2012 21:14
-
-
Save rugbyprof/1871465 to your computer and use it in GitHub Desktop.
Php Iterative Directory Traversal
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 | |
//From php.net comments written by: | |
//donovan dot pp at gmail dot com | |
function dir_tree($dir) { | |
$path = ''; | |
$stack[] = $dir; | |
while ($stack) { | |
$thisdir = array_pop($stack); | |
if ($dircont = scandir($thisdir)) { | |
$i=0; | |
while (isset($dircont[$i])) { | |
if ($dircont[$i] !== '.' && $dircont[$i] !== '..') { | |
$current_file = "{$thisdir}/{$dircont[$i]}"; | |
if (is_file($current_file)) { | |
$path[] = "{$thisdir}/{$dircont[$i]}"; | |
} elseif (is_dir($current_file)) { | |
$path[] = "{$thisdir}/{$dircont[$i]}"; | |
$stack[] = $current_file; | |
} | |
} | |
$i++; | |
} | |
} | |
} | |
return $path; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment