Home  >  Article  >  Backend Development  >  PHP删除符合条件的整个目录,符合条件整个目录_PHP教程

PHP删除符合条件的整个目录,符合条件整个目录_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:57:26741browse

PHP删除符合条件的整个目录,符合条件整个目录

php

    /**
    *    @name       delFile函数与delDir函数一起使用, 删除符合条件的整个目录
    *    @param      string  $path   指定操作路径
    *    @return     null
    *    @example    delDir('D:\web\Apache\htdocs\KeyShareMall\Pc\ThinkPHP');
    */
  
   // 删除目录 function delFile($path) { if (empty($path)) { echo '请指定要操作的文件路径'; 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 ); } } function delDir($path = '') { if (empty($path)) { echo '请指定要操作的文件路径'; 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 . "
"; // 删除含有Zip字符的目录 if (strpos($fileName, 'Zip') !== false) { delFile($path . '/' . $fileName); } else { delDir($path . '/' . $fileName); } } } } closedir ( $handle ); } } delDir('D:\web\Apache\htdocs\KeyShareMall\Pc\ThinkPHP'); ?>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/983850.htmlTechArticlePHP删除符合条件的整个目录,符合条件整个目录 ? php /* * * @name delFile函数与delDir函数一起使用, 删除符合条件的整个目录 * @param string $path...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn