-2

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?

Andrius Solopovas
  • 967
  • 11
  • 41
  • Possible duplicate of [Strange php behavior Recursive folder deletion removes only 527 file rather than all](http://stackoverflow.com/questions/38478760/strange-php-behavior-recursive-folder-deletion-removes-only-527-file-rather-than) – B001ᛦ Jul 20 '16 at 13:53

1 Answers1

0

The problem is with my vagrant homestead box... It works fine on my production service and deletes all the files but same does not apply to local development environment.

Andrius Solopovas
  • 967
  • 11
  • 41