php递归遍历删除文件的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php递归遍历删除文件的方法。分享给大家供大家参考。具体如下:

这个函数稍加修改就可以变成一个递归文件拷贝函数

<?php
function mover($src,$dst) {
$handle=opendir($src);
// Opens source dir.
if (!is_dir($dst)) mkdir($dst,0755);
// Make dest dir.
while ($file = readdir($handle)) {
  if (($file!=".") and ($file!="..")) {
  // Skips . and .. dirs
    $srcm=$src."/".$file;
    $dstm=$dst."/".$file;
    if (is_dir($srcm)) {
    // If another dir is found
     mover($srcm,$dstm);
  // calls itself - recursive WTG
    } else {
     copy($srcm,$dstm);
     unlink($srcm);
  // Is just a copy procedure is needed
    } // comment out this line
  }
}
closedir($handle);
rmdir($src);
}
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

php提交post数组参数实例分析

本文实例分析了php提交post数组参数的用法。分享给大家供大家参考,具体如下: 首先php中要想从页面传送数组到服务端a,要在页面上多个空间同名,而且对于名称有要求,那就是 name=...

php 抽象类的简单应用

All right, 父类postParent定义为抽象,规定子类必须重新实现 buildHTML()方法,这个方法并没有花括号,如果有不管有没有内容都会报错的。 现在越看越觉得这代码完...

ThinkPHP 模板substr的截取字符串函数详解

ThinkPHP 模板substr的截取字符串函数详解

ThinkPHP 模板substr的截取字符串函数 在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr(...

在PHP中读取和写入WORD文档的代码

复制代码 代码如下:<?  // 建立一个指向新COM组件的索引  $word = new COM(”word.appl...

php intval的测试代码发现问题

<?php $o = 0.1; for($a = 1; $a < 100; $a++){ &n...