note 50660 added to function.rmdir
| From: | czambran at gmail dot com | Date: | Sun, 06 Mar 2005 07:21:43 +0000 |
| Subject: | note 50660 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85991@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50660
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50660&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50660&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50660&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50660&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50660&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50660&report=yes
Search -- http://master.php.net/manage/user-notes.php