note 81160 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:22:09 +0000 |
| Subject: | note 81160 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153239@lists.php.net to get a copy of this message | ||
Note Submitter: lukas at example dot com
----
I've improved the function of vboedefeld at googlemail dot com:
The function worked fine but I had a typo in the variable name I passed to the function, and as a
result I have lost all files (I've had a backup)
So I made the function check first if the passed path is a directory:
<?php
function deltree($f) {
if (is_dir($f)) {
foreach(glob($f.'/*') as $sf) {
if (is_dir($sf) && !is_link($sf)) {
deltree($sf);
rmdir($sf);
} else {
unlink($sf);
}
}
} else {
die("Error: not a directory - $f");
}
}
?>