Created
August 13, 2014 16:17
-
-
Save zhester/d12c3d9d6e11a683795e to your computer and use it in GitHub Desktop.
Another directory listing function that uses a regular expression as a filter.
This file contains 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
/** | |
* Returns a list of all file nodes for a given path. | |
* | |
* @param path The path for which to build a list of file node entries. | |
* @param pattern Optional filter pattern to test each node name against. | |
* The default pattern prevents returning hidden node entries. | |
* @return A list of node entries in the given path. | |
*/ | |
function get_dlist( $path, $pattern = '/^[^.]/' ) { | |
$nodes = []; | |
$dh = opendir( $path ); | |
if( $dh ) { | |
while( ( $node = readdir( $dh ) ) !== false ) { | |
if( preg_match( $pattern, $node ) ) { | |
$nodes[] = $node; | |
} | |
} | |
closedir( $dh ); | |
sort( $nodes ); | |
} | |
return $nodes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment