note 66009 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:25:53 +0000
Subject: note 66009 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153264@lists.php.net to get a copy of this message
Note Submitter: brianleeholub at yahoo dot com ---- this will only work in php5 (scandir). feed this function the path to a directory (INCLUDE TRAILING /) and it'll clean it of all contents (if it contains a directory with more stuff it'll dive down and clean that out). use with care! remove_directory('/path/to/crap/for/deletion/'); function remove_directory($dir) { $dir_contents = scandir($dir); foreach ($dir_contents as $item) { if (is_dir($dir.$item) && $item != '.' && $item != '..') { remove_directory($dir.$item.'/'); } elseif (file_exists($dir.$item) && $item != '.' && $item != '..') { unlink($dir.$item); } } rmdir($dir); }

« previous php.notes (#153264) next »