gpt4 book ai didi

php - 如何快速查找目录中的文件数?

转载 作者:可可西里 更新时间:2023-11-01 00:36:34 25 4
gpt4 key购买 nike

我的系统中的几个目录中有数千个日志文件。大多数情况下,我只需要知道目录中这些文件的数量。我担心这种态度:

$files = count(scandir("logs")) - 2;

不是很有效(内存,文件系统)。我正在考虑一些全局计数器(在添加文件后增加),除非有其他有效的方法?

最佳答案

这些是我扫描大约 30 个文件夹时的总数,每个文件夹大约有 5000 个文件。找不到比 scandir 更快的方法,除了缓存结果(在 memcached 或其他东西中)。

echo count(scandir('logs/'))-2; // 0.140 sec

echo system('find "logs/ | wc -l'); // 0.300 sec

echo system('ls -l logs/ | wc -l'); // 1.200 sec

echo count(glob('logs/*',GLOB_NOSORT)); // 1.800 sec

关于php - 如何快速查找目录中的文件数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6211687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com