![](/img/trans.png)
[英]PHP - is it possible to list only directories and using braces at the same time with glob?
[英]PHP: Using glob() to list *.txt and directories?
而不是列出所有文件和目录
foreach(glob("/*") as $file) {
...
}
有没有办法过滤* .txt文件和目录? 因为在这个例子中
foreach(glob("/*.txt") as $file) {
...
}
将仅获取* .txt文件,而不获取目录。 但是只列出目录,这将起作用:
foreach(glob("/*", GLOB_ONLYDIR) as $file) {
...
}
但会忽略* .txt文件。 我试图避免在读取目录后使用preg_match()或类似的操作,因为如果有大约5000个不必要的文件(带有* .jpg,*。png的图像文件),它将浪费服务器资源。
谢谢。
还尝试了GLOB_BRACE,但没有成功,因此必须使用以下代码:
$aDir1 = glob('/*.txt'); // current directory
$aDir2 = glob('/*/*.txt'); // subdirectory, one level below
$aDir = asort(array_merge($aDir1, $aDir2));
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.