Jump to content

delete_directory


westman
 Share

Recommended Posts

Hi all,
I am working with some old script to remove files and folders.
 

$directory = "../pics/$id";
function delete_directory($directory, $empty=false)
{
  if(substr($directory,-1) == DIRECTORY_SEPARATOR){
    $directory = substr($directory,0,-1);  }
  
  if(!is_dir($directory) || !is_readable($directory)){
    return false;  }
  
  else{
    $handle = opendir($directory);
    while (false !== ($item = readdir($handle))){
      if($item != '.' && $item != '..'){
        $path = $directory.DIRECTORY_SEPARATOR.$item;
        if(is_dir($path)){
          delete_directory($path);	}
        
		else{
          unlink($path);
        }
      }
    }
    closedir($handle);
 
    if($empty == false){
      if(!rmdir($directory)){
        return false;	}
    }
    return true;	}
}	
delete_directory($directory);

Will this still work in the new php version?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...