Recursive remove folder

This commit is contained in:
Jeroen De Meerleer 2021-08-05 18:15:56 +02:00
parent b65ae0ab71
commit 5af9af91e1
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -50,16 +50,15 @@ class RefreshCommand extends Command
return Command::FAILURE; return Command::FAILURE;
} }
function recursiveRemoveDirectory($directory) function recursiveRemoveDirectory($dir)
{ {
foreach(glob($directory . "/*") as $file)
{ $files = array_diff(scandir($dir), array('.', '..'));
if(is_dir($file)) {
$this->recursiveRemoveDirectory($file); foreach ($files as $file) {
} else { (is_dir("$dir/$file")) ? $this->recursiveRemoveDirectory("$dir/$file") : unlink("$dir/$file");
unlink($file);
}
} }
rmdir($directory);
return rmdir($dir);
} }
} }