Created
January 13, 2013 20:13
-
-
Save AlexanderC/4525951 to your computer and use it in GitHub Desktop.
Spherus alt method
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
<?php | |
//... | |
private static function ReadDirectory($path, $includeHiddenFiles = false, $readDirectories = true, $readFiles = true) | |
{ | |
$result = []; | |
if (!$readFiles && !$readDirectories) { | |
return $result; | |
} | |
$flags = $includeHiddenFiles | |
? \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS | |
: \FilesystemIterator::CURRENT_AS_FILEINFO; | |
$items = iterator_to_array(new \FilesystemIterator($path, $flags)); | |
if($readFiles) { | |
$result['files'] = array_filter($items, function(\DirectoryIterator $it) { | |
return $it->isFile(); | |
}); | |
} | |
if($readDirectories) { | |
$result['folders'] = array_filter($items, function(\DirectoryIterator $it) { | |
return $it->isDir(); | |
}); | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment