0

I have some code I'm using I found on here, but would like to know how it actually works and what it's doing.

I gather it iterates through the various files and folders and removes them, but would like to know the mechanics so that I can make adjustments to target specific folders and it's contents.

function recursiveDeleteTD($dirPath, $deleteParent){

foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
    $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
}
if($deleteParent) rmdir($dirPath);

}

Any thoughts on this would be greatly appreiciated :)

Thanks

Rob

0 Answers0