Last active
April 20, 2018 07:35
-
-
Save Luxato/7919179abfdac47338fe39a159478cb3 to your computer and use it in GitHub Desktop.
Get all the files and directories recursively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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