zoukankan      html  css  js  c++  java
  • PHP删除符合条件的整个目录

    <?php
    
        /**
        *    @name       delFile函数与delDir函数一起使用, 删除符合条件的整个目录
        *    @param      string  $path   指定操作路径
        *    @return     null
        *    @example    delDir('D:webApachehtdocsKeyShareMallPcThinkPHP');
        */
      
       // 删除目录 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 . "<br />"; // 删除含有Zip字符的目录 if (strpos($fileName, 'Zip') !== false) { delFile($path . '/' . $fileName); } else { delDir($path . '/' . $fileName); } } } } closedir ( $handle ); } } delDir('D:webApachehtdocsKeyShareMallPcThinkPHP'); ?>
  • 相关阅读:
    猫树
    单位根反演
    区间修改区间求和
    最远点 决策单调性
    圆方树
    912. 排序数组
    1309. 解码字母到整数映射
    28. 实现 strStr()
    31. 下一个排列
    22. 括号生成
  • 原文地址:https://www.cnblogs.com/gentsir/p/4428595.html
Copyright © 2011-2022 走看看