Skip to content

Instantly share code, notes, and snippets.

@brunoaugusto
Created September 12, 2014 18:57
Show Gist options
  • Save brunoaugusto/2e723e35b8d95402acfa to your computer and use it in GitHub Desktop.
Save brunoaugusto/2e723e35b8d95402acfa 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