Created
April 29, 2015 04:44
-
-
Save TechplexEngineer/9feb3e26e75e9dce6c6e to your computer and use it in GitHub Desktop.
Recursive print directory tree
This file contains hidden or 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 | |
| function scandir_folders($d, $blacklist = array('.', '..')) { | |
| return array_filter(scandir($d), function ($f) use($d, $blacklist) { | |
| return is_dir($d . DIRECTORY_SEPARATOR . $f) && !in_array($f, $blacklist); | |
| }); | |
| } | |
| function scandir_all($d, $blacklist = array('.', '..')) { | |
| return array_filter(scandir($d), function ($f) use($d, $blacklist) { | |
| return !in_array($f, $blacklist); | |
| }); | |
| } | |
| //@todo probably should limit the depth | |
| function recurse_scandir($d) | |
| { | |
| foreach (scandir_all($d) as $item) | |
| { | |
| $path = $d.'/'.$item; | |
| if (is_dir($path)) | |
| { | |
| echo "$path"; | |
| echo "<ul>"; | |
| recurse_scandir($path); | |
| echo "</ul>"; | |
| } | |
| else | |
| { | |
| echo "<li>"; | |
| echo '<a href="'.$path.'/'.$item.'">'.$item.'</a>'; | |
| echo "</li>"; | |
| } | |
| } | |
| } | |
| echo "<h1>Directory Tree</h1>"; | |
| recurse_scandir('./src') | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment