note 22329 deleted from function.rmdir by aidan

From: Date: Sun, 05 Sep 2004 07:15:14 +0000
Subject: note 22329 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76031@lists.php.net to get a copy of this message
Note Submitter: MasterNES at aol dot com ---- Here's mine, which is a bit safer. It immediately cancels the deletion if anything couldn't be deleted. // Enables deletion of directory if not empty function clr_dir($dir) { if(@ ! $opendir = opendir($dir)) { return false; } while(false !== ($readdir = readdir($opendir))) { if($readdir !== '..' && $readdir !== '.') { $readdir = trim($readdir); if(is_file($dir.'/'.$readdir)) { if(@ ! unlink($dir.'/'.$readdir)) { return false; } } elseif(is_dir($dir.'/'.$readdir)) { // Calls itself to clear subdirectories if(! clr_dir($dir.'/'.$readdir)) { return false; } } } } closedir($opendir); if(@ ! rmdir($dir)) { return false; } return true; }

« previous php.notes (#76031) next »