note 72435 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:25:01 +0000
Subject: note 72435 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153258@lists.php.net to get a copy of this message
Note Submitter: PHPcoder at cyberpimp dot sexventure dot com ---- This is my solution for removing directories: <?php /* Function to remove directories, even if they contain files or subdirectories. Returns array of removed/deleted items, or false if nothing was removed/deleted. by Justin Frim. 2007-01-18 Feel free to use this in your own code. */ function rmdirtree($dirname) { if (is_dir($dirname)) { //Operate on dirs only $result=array(); if (substr($dirname,-1)!='/') {$dirname.='/';} //Append slash if necessary $handle = opendir($dirname); while (false !== ($file = readdir($handle))) { if ($file!='.' && $file!= '..') { //Ignore . and .. $path = $dirname.$file; if (is_dir($path)) { //Recurse if subdir, Delete if file $result=array_merge($result,rmdirtree($path)); }else{ unlink($path); $result[].=$path; } } } closedir($handle); rmdir($dirname); //Remove dir $result[].=$dirname; return $result; //Return array of deleted items }else{ return false; //Return false if attempting to operate on a file } } ?>

« previous php.notes (#153258) next »