当前位置: 移动技术网 > IT编程>开发语言>PHP > php递归遍历删除文件的方法

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

2018年06月24日  | 移动技术网IT编程  | 我要评论

大商网上商城,贝塔有几个助手,贵州都市网

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网