note 56455 deleted from function.rmdir by mazzanet

From: Date: Sat, 03 Sep 2005 06:44:38 +0000
Subject: note 56455 deleted from function.rmdir by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94685@lists.php.net to get a copy of this message
Note Submitter: mgeiser at gmail dot com ---- 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"; } } } ?>

« previous php.notes (#94685) next »