note 50660 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:29:15 +0000 |
| Subject: | note 50660 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153278@lists.php.net to get a copy of this message | ||
Note Submitter: czambran at gmail dot com
----
A quick note on the function posted by Daniellehr[-at-]gmx[-dot-]de, the function as it is will
delete everything inside the directory but the directory. The problem is that the function does not
close the directory before executing the rmdir line. Here is the corrected function:
function delDir($dirName) {
if(empty($dirName)) {
return true;
}
if(file_exists($dirName)) {
$dir = dir($dirName);
while($file = $dir->read()) {
if($file != '.' && $file != '..') {
if(is_dir($dirName.'/'.$file)) {
delDir($dirName.'/'.$file);
} else {
@unlink($dirName.'/'.$file) or die('File
'.$dirName.'/'.$file.' couldn\'t be deleted!');
}
}
}
$dir->close();
@rmdir($dirName) or die('Folder '.$dirName.' couldn\'t be
deleted!');
} else {
return false;
}
return true;
}