Search

PHP code for recursive deletion PDF Print E-mail
User Rating: / 0
PoorBest 
Programming - PHP
Wednesday, 01 July 2009 20:04

 

 

/* This code will delete all the contents of a directory including sub directories*/

 

$path="/image/icon/";

//give the complete path here

deletedir($path);

function deletedir($dir)

{

$iterator = new RecursiveDirectoryIterator($dir);

foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file)

{

if ($file->isDir())

{rmdir($file->getPathname());

}

else

{

unlink($file->getPathname());

}

}

rmdir($dir);

}

?>



Add this page to your favorite Social Bookmarking websites
 
Last Updated on Thursday, 02 July 2009 06:35
 

Add comment


Security code
Refresh

We have 96 guests online