English 中文(简体)
找到含有特定项目的名录的最快途径
原标题:fastest way to locate directories containing a specific item

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;
}

不幸的是,对于最大的管理机构来说,这一行动可以耗时一小时。 如果我去掉过滤器,只插入阵列中看到的每一个项目,它将在几秒中完成。

是否有更快的办法来做到这一点?

最佳回答

我对拉开这一卡表示仇恨,但你重新做些什么可以更快地利用书记或甚至窗户口来完成——PHP可能不是这里工作的适当工具。 一项系统电话(甚至从PHP内部)至dir /s /bfind,将给你一份现有所有档案清单,然后,你可以比检查每个目录中是否有档案,更快地对这些带动。

我会这样做。

find | grep  /bar/zoo.zip 

我不知道适当的窗户(因为我在机器上安装了WinGnu32 gr),因此我可以在那里帮助你。

Edit:

我有点 around,发现上面指挥的视窗等:

dir /s /b | find "/bar/zoo.zip"
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签