使用php将目录的全部内容复制到另一个目录 [英] Copy entire contents of a directory to another using php
本文介绍了使用php将目录的全部内容复制到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用
copy ("old_location/*.*","new_location/");
但是它说找不到流,找不到真正的*.*
.
but it says it cannot find stream, true *.*
is not found.
任何其他方式
谢谢 戴夫
推荐答案
It seems that copy only handle single files. Here is a function for copying recursively I found in this note on the copy documentation page:
<?php
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
?>
这篇关于使用php将目录的全部内容复制到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文