Skip to content

Instantly share code, notes, and snippets.

@kopepasah
Last active December 19, 2015 22:09
Show Gist options
  • Save kopepasah/6025291 to your computer and use it in GitHub Desktop.
Save kopepasah/6025291 to your computer and use it in GitHub Desktop.
This is will list the files with in a directory, including files within subdirectories. The output is a MediaWiki format list of the files grouped together by similar parts.
<?php
function list_directory_files( $directory ) {
$files = array_diff( scandir( $directory ), array( '.', '..', 'list-files.php', '.DS_Store' ) );
foreach ( $files as $file ) {
if ( dirname( __FILE__ ) == $directory ) {
if ( is_dir( $directory . '/' . $file ) ) {
$folder = $file . '.php';
}
if ( $folder != $file ) {
if ( is_dir( $file ) ) {
echo '</br>=====' . ucwords( str_replace( '-', ' ', $file ) ) . '=====</br>';
echo '*[[Exchange_Theme_Templates:_' . $file . '.php|' . $file . '.php]]</br>';
} else {
echo '</br>=====' . ucwords( str_replace( '-', ' ', str_replace( '.php', '', $file ) ) ) . '=====</br>';
echo '*[[Exchange_Theme_Templates:_' . $file . '|' . $file . ']]</br>';
}
}
} else {
if ( ! is_dir( $directory . '/' . $file ) ) {
echo '*[[Exchange_Theme_Templates:_' . str_replace( dirname( __FILE__ ) . '/', '', $directory ) . '/' . $file . '|' . str_replace( dirname( __FILE__ ) . '/', '', $directory ) . '/' . $file . ']]</br>';
}
}
if ( is_dir( $directory . '/' . $file ) )
list_directory_files( $directory . '/' . $file );
}
}
list_directory_files( dirname( __FILE__ ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment