note 71499 deleted from function.unlink by philip

From: Date: Wed, 07 Feb 2007 05:01:47 +0000
Subject: note 71499 deleted from function.unlink by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123021@lists.php.net to get a copy of this message
Note Submitter: heavyraptor ---- The following function easily removes the Directory $dir and all its content. <?php function rmdirr($dir) { if (substr($dir,-1) != "/") $dir .= "/"; if (!is_dir($dir)) return false; if (($dh = opendir($dir)) !== false) { while (($entry = readdir($dh)) !== false) { if ($entry != "." && $entry != "..") { if (is_file($dir . $entry) || is_link($dir . $entry)) unlink($dir . $entry); else if (is_dir($dir . $entry)) rmdirr($dir . $entry); } } closedir($dh); rmdir($dir); return true; } return false; } // Example: $dir = "./MyDirectory/"; $res = rmdirr($dir); // Bye bye if ($res == true) print "$dir got deleted."; else print "Error while trying to delete $dir."; ?> Have fun

« previous php.notes (#123021) next »