Recursive Delete Function

Home / PHP / Recursive Delete Function

Sometimes we need to delete any particular directory or all files and sub directory in one specific directory. People who have computer repair training may need to do this from time to time. The following function is useful if you wish to clear out all files and folders in one particular directory.

function DELETE_RECURSIVE_DIRS($dirname) 
{ // recursive function to delete 
  // all subdirectories and contents: 
    if($file!="." && $file!="..") 
      if(!is_dir($dirname."/".$file))unlink ($dirname."/".$file); 
      else DELETE_RECURSIVE_DIRS($dirname."/".$file); 
  return true; 

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *