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自定义分页类完整实例

本文实例讲述了php自定义分页类。分享给大家供大家参考,具体如下: <?php header("Content-type:text/html;Charset=utf-8...

php初学者写及时补给skype用户充话费的小程序

其实加在一起有几十个,但因为需要操作的数据比较多,就在后面加了一段小程序来解决.可以处理昨天没有处理到的数据,具体如下:复制代码 代码如下:$handle = mysql_connect...

PHP+Ajax简单get验证操作示例

PHP+Ajax简单get验证操作示例

本文实例讲述了PHP+Ajax简单get验证操作。分享给大家供大家参考,具体如下: 1、显示页面代码 index.html <!DOCTYPE html> <htm...

php实现连接access数据库并转txt写入的方法

本文实例讲述了php实现连接access数据库并转txt写入的方法。分享给大家供大家参考,具体如下: 这里的代码实现PHP读取手机归属地 并导入txt文件的功能(文章末尾附手机归属地 数...

自己在做项目过程中学到的PHP知识收集

1 在SQL语句中可通过添加限制条件:left(text,20)只取text文本的前20个字; 2 可以用limit fromRecord, RecordNum 来作为分页使用,比如li...