I have tried two recursive scripts to wipe the contents of the folder:
Fist one:
function clearDirectory($path)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(get_home_path().$path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $filename => $fileInfo) {
if ($fileInfo->isDir()) {
rmdir($filename);
} else {
unlink($filename);
}
}
}
Second one:
function rrdir($path)
{
$src = get_home_path() . $path;
$dir = opendir($src);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
$full = $src . '/' . $file;
if ( is_dir($full) ) {
rrmdir($full);
}
else {
unlink($full);
}
}
}
closedir($dir);
rmdir($src);
}
In both instances it does the same thing. But I encounter strange problem that it does not remove all files it only does so for 527 out of 706.
If I run any of these scripts twice it removes all of the files... But does not do so from the first time.
Has nothing to do with linux or any other permission tested and all permission are in order.
There are no errors thrown in logs everything works smoothly with these both scripts the problem is that they don't delete all files from the first time.
I am running windows 10 x64, with Vagrant and Homestead virtual box. Tested rm -f *
it works fine. What am I doing wrong?