I have a folder with 706 files in it. Which simply stores cropped thumbnails. From time to time I need it to be wiped clean. So I created function that utilizes the RecursiveDirectoryIterator to wipe those files. Here is my function:
function wipeDir($path)
{
$i = 0;
$src = realpath(get_home_path().$path);
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $filename => $fileInfo) {
$i++;
unlink($filename);
}
return $i;
}
The problem is that if I use unlink function it processes only 527 files and $i= 527 when I run this function twice it wipes all the files within this directory, but if I comment the unlink function $i=706 which is a correct number of items within this folder. Somehow unlink function breaks from the iterator when it reaches files 527. Does anyone know why is that?