Tag: End file Open System pre else open dir current
1<?PHP2 3 //recursively delete a directory4 $path= "d:/a";5 //call a recursive function6 $res= Diguirmdir ($path);7 //Output Results8 Var_dump($res);9 Ten functionDiguirmdir ($path){ One A //Open Directory handle - $handle=Opendir($path); - the //Readdir () reads entries from the directory handle - //Returns the file name of the next file in the directory. File names are returned in a sort order in the file system - while(false!==$filename=Readdir($handle)){ - if($filename= = '. ' | |$filename= = '.. ') {//Skip over ... Folder + Continue; - } + A //determine if the directory at if(Is_dir($path.‘ /‘.$filename)) { - $current _func=__function__; - //is directory, recursive delete - $current _func= ($path.‘ /‘.$filename); -}Else{ - //is file, delete in unlink($path.‘ /‘.$filename);//unlink () Delete file return bool - } to } + //Directory deletion complete - Closedir($handle);//Close the directory handle the return rmdir($path);//Delete directory return results *}
Recursive removal of PHP