文章主要介绍了php递归遍历删除文件的方法,涉及php遍历文件操作的相关技巧,非常具有实用价值,需要的朋友可以参考下.
本文实例讲述了php递归遍历删除文件的'方法。分享给大家供大家参考。具体如下:
这个函数稍加修改就可以变成一个递归文件拷贝函数
?
1
2
3
4
5
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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程序设计有所帮助。
算法原理
如果用P表示n个元素的全排列,而Pi表示n个元素中不包含元素i的全排列,(i)Pi表示在排列Pi前面加上前缀i的排列,那么n个元素的全排列可递归定义为:
① 如果n=1,则排列P只有一个元素i;