Mit folgender Klasse/Funktion können mit der Programmiersprache PHP Verzeichisse und darin enthaltene Dateien rekursiv gelöscht werden.
abstract class DirHelper {
/**
* Verzeichnis mit Inhalten recursiv löschen
* @param string $path
*
* @return bool
*/
public static function rmDir(string $path) : bool {
if (is_dir($path)) {
$hPath = opendir($path);
if ($hPath) {
while ($file = readdir($hPath)) {
if ($file != "." && $file != "..") {
if (!is_dir($path."/".$file)) {
unlink($path."/".$file);
} else {
self::rmDir($path.'/'.$file);
}
}
}
closedir($hPath);
}
rmdir($path);
return true;
}
return false;
}
}
Aufruf
DirHelper:: rmDir('{Pfad}');