note 90668 deleted from function.rmdir by aidan

From: Date: Tue, 19 May 2009 07:56:37 +0000
Subject: note 90668 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155712@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- There should be added a new parameter which allows to specify that I want to delete a folder with all files in it. The following function does not delete subdirectories but all files which is often enough. <?php public static function RemoveDirectory($Dir) { if (!is_dir($Dir)) return true; $Files = scandir($Dir); foreach ($Files as $File) { if ($File == "." || $File == "..") continue; if (!Utils::DeleteFile($Dir.$File)) return false; } if (rmdir($Dir)) return true; Log::Error("Could not delete directory: '$Dir'"); return false; } public static function DeleteFile($File) { if (!is_file($File)) return true; if (unlink($File)) return true; Log::Error("Could not delete file: '$File'"); return false; } ?>

« previous php.notes (#155712) next »