Skip to content

Instantly share code, notes, and snippets.

@thorbrink
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thorbrink/27aa6daa49deb7c609e2 to your computer and use it in GitHub Desktop.
Save thorbrink/27aa6daa49deb7c609e2 to your computer and use it in GitHub Desktop.
Get all files in folder recursively
<?php
function get_recursive_files_array( $dir, $files = null ) {
$files_in_folder = scandir( $dir );
$files = ( null === $files ) ? array() : $files;
foreach ( $files_in_folder as $file ) {
if ( ! is_dir( $dir . $file ) ) {
$files[] = $dir . $file;
} elseif ( '..' !== $file && '.' !== $file ) {
$files = get_recursive_files_array( $dir . $file . '/' );
}
}
return $files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment