PHP deletes the entire directory that matches the criteria

Source: Internet
Author: User
 
    PHP
 /** * @name The Delfile function is used with the Deldir function to delete the entire directory that matches the condition * @param string $path Specify the action path * @return    Null * @example deldir (' D:\web\Apache\htdocs\KeyShareMall\Pc\ThinkPHP '); */
  
Delete DirectoryfunctionDelfile ($path) { if(Empty($path)) { Echo' Specify the file path to be manipulated '; return false; } if($handle=Opendir($path )) { while(false!== ($fileName=Readdir($handle ))) { if($fileName!= "." &&$fileName!= ".." ) { if(Is_file($path. '/' .$fileName)) { unlink($path. '/' .$fileName); } if(Is_dir($path. '/' .$fileName) {delfile ($path. '/' .$fileName); } } } rmdir($path); Closedir($handle ); } } functionDeldir ($path= '') { if(Empty($path)) { Echo' Specify the file path to be manipulated '; return false; } Else { $path=Str_replace('\\', '/',$path); } if($handle=Opendir($path)) { while(false!== ($fileName=Readdir($handle ))) { if($fileName!= "." &&$fileName!= ".." ) { if(Is_dir($path. '/' .$fileName)) { Echo $fileName. "
"; //Delete a directory containing zip characters if(Strpos($fileName, ' Zip ')!==false) {Delfile ($path. '/' .$fileName); } Else{Deldir ($path. '/' .$fileName); } } } } Closedir($handle ); } } deldir (' D:\web\Apache\htdocs\KeyShareMall\Pc\ThinkPHP ');?>

The above describes the PHP removal of the entire directory, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.