note 50161 added to function.rmdir

From: Date: Sun, 20 Feb 2005 09:55:43 +0000
Subject: note 50161 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-85265@lists.php.net to get a copy of this message
If you want to delete a folder with its all content and sub-content you can use this recursive-working function (WARNING: after using the function the folder is completely deleted!): <?php function delDir($dirName) { if(empty($dirName)) { return; } 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!'); } } } @rmdir($dirName.'/'.$file) or die('Folder '.$dirName.'/'.$file.' couldn\'t be deleted!'); } else { echo 'Folder "<b>'.$dirName.'</b>" doesn\'t exist.'; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50161 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50161&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50161&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50161&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50161&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50161&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50161&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85265) next »