I need to exclude all files and folders from a certain directories while doing the recursion. I have this code so far :
$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
}
}
However this subpath will only match for children and and not files and sub directories off the children. i.e For a directory structure of Foo/bar/hello.php. If you add Foo to the exclude list hello.php would still come in the result.
Does anyone have a solution for this ?
Replace :
By something like :
And you implement the function :
But that's not a very good way because you will recursivly get into useless directories even if they are very big and deep. In your case, I'll suggest you to do a old-school recursive function to read your directory :
If you try
directory_reader(".", array("aDirectoryToIngore"))
, it will not be read at all.