Hi PHP community, here I bring a very simple and interesting function that
I made for a project, it's objetive is "to list path files in a directory
with the possibility of using filters and exclusions".
What do you think about?
-----------------------
function get_files($path, &$result, Array $exclusions, Array $filters)
{
@$dir_content = scandir($path);
if ($dir_content)
{
$end = count($dir_content);
$i = 2;
for ($i; $i < $end; $i++)
{
$path_and_element = $path.'/'.$dir_content[$i];
if (array_search($path_and_element, $exclusions) === false)
{
if (array_search(substr($dir_content[$i],
strlen($dir_content[$i]) - 4), $filters) !== false)
{
$result[] = $path_and_element;
}
if (is_dir($path_and_element))
{
get_files($path_and_element, $result, $exclusions,
$filters);
}
}
}
}
}
$path = '/var/www';
$result = array();
$exclusions = array('/var/www/drupal', '/var/www/wp');
$filters = array('.php');
get_files($path, $result, $exclusions, $filters);
echo "<pre>";
print_r($result);
die();
------------------------------------------------------------
Greetings!!!!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php