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

yipeiwu_com5年前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程序设计有所帮助。

相关文章

提示Trying to clone an uncloneable object of class Imagic的解决

使用网上流传的一个程序实现pdf截图为png,需要使用Imagic扩展。在windows下安装完后提示: Fatal error: Trying to clone an unclonea...

PHP 数组和字符串互相转换实现方法

复制代码 代码如下:$array=explode(separator,$string); $string=implode(glue,$array);使用和理解这两个函数的关键之处是分隔符...

隐性调用php程序的方法

本文实例讲述了隐性调用php程序的方法。分享给大家供大家参考。具体如下: 复制代码 代码如下:<mce:script language = "javascript" src = "...

PHP命名空间定义与用法实例分析

PHP命名空间定义与用法实例分析

本文实例讲述了PHP命名空间定义与用法。分享给大家供大家参考,具体如下: php的命名空间的样式跟linux的路径很相似。 我们使用文件的路径作为命名空间。 定义命名空间 MVC\Mo...

PHP中的命名空间详细介绍

概述 PHP对于命名空间的支持,经历了一段艰难的旅程。幸运的是,PHP从5.3开始引入了命名空间。自从PHP引入了命名空间,PHP代码的适用结构也得到了大大的改善。许多编程语言早就有了命...