当前位置:首页 > PHP教程 > PHP高级教程

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


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!