We all know we can find a PHP code to delete a directory, but to delete a directory will thousands and millions of files in it? Here’s the coding which is quite a hassle to find, and I’m sharing it with y’all.
function del_dir($dir)
{
$res = @opendir($dir);if(!$res) return;
while(($file = readdir($res)) !== false)
{
if($file !== '.' && $file !== '..')
{
$f = $dir . '/' . $file;
if(is_dir($f))
{
del_dir($f);
}
else
{
@unlink($f);
}
}
}
closedir($res);
@rmdir($dir);
}
Save the code above to a single PHP file (eg: deleteall.php). Then on the file where you want to execute this function, place this code.
$dir = "FOLDER_DIRECTORY";
include('deleteall.php');
del_dir($dir);
…And viola! But always remember that there should be a prompt before the the code is execute.
Otherwise, you end up mistakenly deleting the wrong stuff! |