在目录中搜索与特定大小匹配的文件-Windows/PHP


Search directory for files matching a certain size - Windows/PHP

使用IIS6和PHP运行Windows Server 2003系统。

我有一个图像目录,大约20000张。我需要得到一个文件的列表,匹配一定的大小9919字节。这些是空白/通用图像。我将使用图像列表与图像提供商进行检查,看看是否有更新的图像可用。

在Windows、PHP或其他命令行实用程序中,我是否可以在系统上安装一种方法来获取这些文件的列表,而无需扫描目录中的每个文件以确定文件大小。

DirectoryIterator类将允许您快速迭代图像,它为每个项目返回的SPL FileObject将允许您查找文件大小。

foreach (new DirectoryIterator('path/to/image/directory') as $item) {
     if ($item->isFile() && $item->getSize() == 9919) {
           // your code to handle each matching file here...
     }
}

SplFileObject目录