Suche ein PHP Script, um Verzeichnisse zu löschen
Wie man Verzeichnisse löscht, weiß ich natürlich auch, aber wie löscht man volle verzeichnisse löscht...
Also ich brauche ein Script (keinen Dateimanager oder so etwas), das alle Dateien aus einem Verzeichnis löscht, und dann das Verzeichnis löscht!
Please also mark the comments that contributed to the solution of the article
Content-Key: 47094
Url: https://administrator.de/contentid/47094
Printed on: April 18, 2024 at 15:04 o'clock
1 Comment
Hi,
hier mal ein kl. Script. Funktionieren tut es!
Aufrufen der Funktion sieht so aus:
Gruß
Dani
hier mal ein kl. Script. Funktionieren tut es!
function rm_dir($dir)
{
$stack = array($dir);
while (count($stack))
{
$dir = end($stack);
$dh = opendir($dir);
if(!$dh) {trigger_error('clear_tmp_dir: unable to opendir ' . $dir, E_USER_ERROR);}
while(($file = readdir($dh)) !== false)
{
if($file == '.' or $file == '..')
{
continue;
}
if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {$stack = $dir . DIRECTORY_SEPARATOR . $file;}
else if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {unlink($dir . DIRECTORY_SEPARATOR . $file);}
else {trigger_error('clear_tmp_dir: ignoring ' . $dir .DIRECTORY_SEPARATOR . $file, E_USER_ERROR);}
}
if(end($stack) == $dir)
{
rmdir($dir);
array_pop($stack);
}
}
}
...
rmdir ("C:\emp");
...
Dani