note 90668 added to function.rmdir

From: Date: Mon, 04 May 2009 01:09:23 +0000
Subject: note 90668 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-154169@lists.php.net to get a copy of this message
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. 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; } ---- Server IP: 190.54.16.132 Probable Submitter: 201.246.84.152 ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- https://master.php.net/note/edit/90668 Del: integrated -- https://master.php.net/note/delete/90668/integrated Del: useless -- https://master.php.net/note/delete/90668/useless Del: bad code -- https://master.php.net/note/delete/90668/bad+code Del: spam -- https://master.php.net/note/delete/90668/spam Del: non-english -- https://master.php.net/note/delete/90668/non-english Del: in docs -- https://master.php.net/note/delete/90668/in+docs Del: other reasons-- https://master.php.net/note/delete/90668 Reject -- https://master.php.net/note/reject/90668 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154169) next »