【发布时间】:2012-09-17 06:30:07
【问题描述】:
在进行递归时,我需要从某个目录中排除所有文件和文件夹。到目前为止我有这个代码:
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($websiteRoot.$file["filepathfromroot"]));
foreach ($it as $currentfile)
{
if (!$it->isDot()&&$it->isFile()&&!in_array($it->getSubPath(), $file["exclude-directories"])) {
//do something
}
}
但是,此子路径仅匹配子路径,而不匹配子路径的文件和子目录。即对于 Foo/bar/hello.php 的目录结构。如果将 Foo 添加到排除列表 hello.php 仍然会出现在结果中。
有没有人可以解决这个问题?
【问题讨论】:
-
这不是因为您使用的是主要对象,而不是它本身的文件表示吗?例如。
$it->isDot()应该是$currentFile->isDot() -
我更改了它,但当前文件是一个 splfileinfo 对象,它没有 getsubpath 函数或 isdot 函数。
标签: php directory-listing