Recursive removal of PHP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.