note 75594 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:23:59 +0000
Subject: note 75594 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153254@lists.php.net to get a copy of this message
Note Submitter: babca (plutanium.cz) ---- Improvement of function from "brousky - gmail": -Removes a directory and everything in it -After calling this function the current working directory (cwd) of the script won't be changed -Function returns true/false <?php function full_rmdir($dirname) { if ($dirHandle = opendir($dirname)) { $old_cwd = getcwd(); chdir($dirname); while ($file = readdir($dirHandle)) { if ($file == '.' || $file == '..') continue; if (is_dir($file)) { if (!rmdir_rf($file)) return false; } else { if (!unlink($file)) return false; } } closedir($dirHandle); chdir($old_cwd); if (!rmdir($dirname)) return false; return true; } else { return false; } } ?> Enjoy :)

« previous php.notes (#153254) next »