note 56455 added to function.rmdir

From: Date: Sat, 03 Sep 2005 04:05:08 +0000
Subject: note 56455 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-94681@lists.php.net to get a copy of this message
I wrote a function that will try to delete a folder, it will fail if the folder is not empty, so if the folder is empty it will open the folder and delete all files. Once all files are deleted it will try and delete the folder again. Works perfect. <?php function removeDir($dir) { $path = $dir; if($rm = rmdir($path) == TRUE) { echo "Success"; } else { if($check_dir = opendir($path)) { while($file = readdir($checkDir)) { unlink($path . "/" .$file); } } if($rm = rmdir($path) == TRUE) { echo "Success"; } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56455 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56455&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56455&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56455&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56455&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56455&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56455&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56455&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94681) next »