note 25639 deleted from function.rmdir by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 07 Aug 2004 23:47:27 +0000 |
| Subject: | note 25639 deleted from function.rmdir by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74169@lists.php.net to get a copy of this message | ||
Note Submitter: ian@opensystems.net.au
----
recusive function to empty a directory
function delete_all_from_dir($Dir){
// delete everything in the directory
if ($handle = @opendir($Dir)) {
while (($file = readdir($handle)) !== false) {
if ($file == "." || $file == "..") {
continue;
}
if (is_dir($Dir.$file)){
// call self for this directory
delete_all_from_dir($Dir.$file."/");
chmod($Dir.$file,0777);
rmdir($Dir.$file); //remove this directory
}else {
chmod($Dir.$file,0777);
unlink($Dir.$file); // remove this file
}
}
}
@closedir($handle);
}