在 php.ini 中获取给定目录下的所有子目录列表和所有文件的另一个列表的最佳方法是什么?只要我可以从 php 中使用它(例如 c/java/python/... 程序),我就可以使用非纯 php 代码。比纯 递归
更快的东西,某种语言中内置的东西(因为这些东西往往很快。)
最佳答案
看看 RecursiveDirectoryIterator
:
foreach (new RecursiveDirectoryIterator('yourDir') as $file) {
// you don't want the . and .. dirs, do you?
if ($file->isDot()) {
continue;
}
if ($file->isDir()) {
// dir
} else {
// file
}
}
关于php 获取所有子目录和所有文件的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8465813/