Hi! I'm Gordon Mackay, a web developer from the Highlands of Scotland. On this site you will find my photos, free CSS templates, free Adobe Fireworks graphics and some PHP code to use in your projects. Enjoy!
This is a handy PHP function (I can’t remember where I found it) which performs a recursive deletion of every file in a given directory. I’ve been using it to periodically flush cache files created by my CMS on this site.
function destroy($dir) { $mydir = opendir($dir); while(false !== ($file = readdir($mydir))) { if($file != ”.” && $file != ”..”) { chmod($dir.$file, 0777); if(is_dir($dir.$file)) { chdir(’.’); destroy($dir.$file.’/’); rmdir($dir.$file) or die(‘No deletey ’.$dir.$file); } else unlink($dir.$file) or die(‘No deletey ’.$dir.$file); } } closedir($mydir); }
Set the server path to the directory:
define(‘PATH’, ”/path/to/directory/”);
Then let rip…
destroy(PATH);
Have fun, but use with caution!
Comment via Twitter
© All text and images copyright 2013 Gordon Mackay. All Rights Reserved.