Skip to content

Instantly share code, notes, and snippets.

@smallsong
Forked from brunoaugusto/directoryListing.php
Created July 5, 2018 08:37
Show Gist options
  • Save smallsong/cdd3b70f5ea4679190023ae65bb7dbfa to your computer and use it in GitHub Desktop.
Save smallsong/cdd3b70f5ea4679190023ae65bb7dbfa to your computer and use it in GitHub Desktop.
Simple script to generate an ASCII graphic tree of given directory
<?php
$directory = './misc';
try {
$iterator = new RecursiveTreeIterator(
new RecursiveDirectoryIterator(
$directory, RecursiveDirectoryIterator::SKIP_DOTS
),
RecursiveIteratorIterator::SELF_FIRST
);
print '<pre>';
foreach( $iterator as $path ) echo str_replace( $directory, '', $path ), "\n";
} catch( UnexpectedValueException $e ) {
printf( 'Directory <strong>%s,</strong> cannot be traversed', $directory );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment