I have a PHP 5.3.4 application running on Windows XP SP3 where I need to index the contents of a directory on a remote PC. The largest directory I m indexing contains around 18,000 items.
This call would locate items like \somepc.mycorp.comfoomydirarzoo.zip
.
// look in all the directories in \somepc.mycorp.comfoo for directories containing a file arzoo.zip
$item_list = GetFileList( \\somepc.mycorp.com\foo , \bar\zoo.zip );
执行如下:
function GetFileList($base_dir, $path_mask)
{
$result= array();
if ($handle = opendir($base_dir))
{
while (false !== ($entry = readdir($handle)))
{
// only add items that match the mask we re looking for
if ($entry != "." &&
$entry != ".." &&
file_exists($base_dir. \$entry\$path_mask ))
{
array_push($result, $entry);
}
}
closedir($handle);
}
return $result;
}
不幸的是,对于最大的管理机构来说,这一行动可以耗时一小时。 如果我去掉过滤器,只插入阵列中看到的每一个项目,它将在几秒中完成。
是否有更快的办法来做到这一点?