我正在使用这个函数递归地获取文件列表,并且它是有效的。
但是,如何修改它,使其忽略在$ignore数组中定义的文件和文件夹?
function directoryScan($path = 'files', $onlyfiles = true, $fullpath = false)
{
$dir = '';
$ignore = array('.','..','cgi-bin','.DS_STORE','thumb.db','.gitignore', 'folder_to_be_ignored');
if (isset($path) && is_readable($path))
{
$dlist = Array();
$dir = realpath($path);
if ($onlyfiles)
{
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
}
else
{
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
}
foreach($objects as $entry => $object)
{
if (!$fullpath)
{
$entry = str_replace($dir, '', $entry);
$entry = $path . $entry;
}
$dlist[] = $entry;
}
vdebug($dlist);
return $dlist;
}
}发布于 2013-01-16 21:01:47
foreach($objects as $entry => $object)
{
if (!in_array($entry, $ignore)
{
if (!$fullpath)
{
$entry = str_replace($dir, '', $entry);
$entry = $path . $entry;
}
$dlist[] = $entry;
}
}https://stackoverflow.com/questions/14358895
复制相似问题