Function to delete a non empty directory - Php

delete_dir

Snippet Code


  
Rate this page :
  [ 0 votes]

This function is used to find and to delete the non empty directory using php

function deleteDirectory($dir) { if ($handle = opendir($dir)) { $array = array(); while (false !== ($file = readdir($handle))) { if ($file != "." amp&$file != "..") { if(is_dir($dir.$file)) { if(!@rmdir($dir.$file)) { //deleteDir($dir.$file.'/'); // Not empty? Delete the files inside it } } else { @unlink($dir.$file); } } } closedir($handle); @rmdir($dir); }

Tags


Ask Questions

Ask Question