note 98499 added to function.rmdir

From: Date: Fri, 18 Jun 2010 22:30:23 +0000
Subject: note 98499 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-170253@lists.php.net to get a copy of this message
This isn't my code, but just thought I would share, since it took me so long to find. This is a function to delete a folder, all sub-folders, and files in one clean move. Just tell it what directory you want deleted, in relation to the page that this function is executed. Then set $empty = true if you want the folder just emptied, but not deleted. If you set $empty = false, or just simply leave it out, the given directory will be deleted, as well. function deleteAll($directory, $empty = false) { if(substr($directory,-1) == "/") { $directory = substr($directory,0,-1); } if(!file_exists($directory) || !is_dir($directory)) { return false; } elseif(!is_readable($directory)) { return false; } else { $directoryHandle = opendir($directory); while ($contents = readdir($directoryHandle)) { if($contents != '.' && $contents != '..') { $path = $directory . "/" . $contents; if(is_dir($path)) { deleteAll($path); } else { unlink($path); } } } closedir($directoryHandle); if($empty == false) { if(!rmdir($directory)) { return false; } } return true; } } ---- Server IP: 192.41.42.26 Probable Submitter: 24.101.80.133 ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- https://master.php.net/note/edit/98499 Del: integrated -- https://master.php.net/note/delete/98499/integrated Del: useless -- https://master.php.net/note/delete/98499/useless Del: bad code -- https://master.php.net/note/delete/98499/bad+code Del: spam -- https://master.php.net/note/delete/98499/spam Del: non-english -- https://master.php.net/note/delete/98499/non-english Del: in docs -- https://master.php.net/note/delete/98499/in+docs Del: other reasons-- https://master.php.net/note/delete/98499 Reject -- https://master.php.net/note/reject/98499 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170253) next »