note 81152 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:22:16 +0000
Subject: note 81152 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153240@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- in case someone is still stuck on PHP4 server, you need to use this improvised function instead of "scandir" PHP5 built-in function: function scanEntireDir($dir) { $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } closedir($dh); return $files; } so this would work quite fine: function delTree($f) { if (is_dir($f)) { foreach($this->scanEntireDir($f) as $item){ if ( (!strcmp($item, '.')) OR (!strcmp($item, '..')) ) continue; delTree($f . "/" . $item); // recurision } rmdir($f); } else{ unlink($f); } // check if deleted? if (is_dir($f)) return false; else return true; } cheers!

« previous php.notes (#153240) next »