Skip to content

Instantly share code, notes, and snippets.

@Luxato
Last active April 20, 2018 07:35
Show Gist options
  • Save Luxato/7919179abfdac47338fe39a159478cb3 to your computer and use it in GitHub Desktop.
Save Luxato/7919179abfdac47338fe39a159478cb3 to your computer and use it in GitHub Desktop.
Get all the files and directories recursively.
<?php
/**
* Get all the files and directories recursively.
*
* @param $dir
* @param array $results
*
* @return array
*/
function getDirContents( $dir, &$results = array() ) {
$files = scandir( $dir );
foreach ( $files as $key => $value ) {
$path = realpath( $dir . DIRECTORY_SEPARATOR . $value );
if ( ! is_dir( $path ) ) {
$results[] = $path;
} else if ( $value != "." && $value != ".." ) {
getDirContents( $path, $results );
$results[] = $path;
}
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment