在php中,重命名函数允许将文件移动到其他文件夹但是,将所有文件从一个文件夹移动到另一个文件夹的最有效方法是什么?
@rename($fail_path, $incoming_path);
不工作
如果我必须实现这一点,我需要
foreach (scandir($fail_path) as $file){
rename($fail_path.$file, $incoming_path.$file);
}
它是否消耗资源/是否有更直接的方法?感谢
是否尝试shell_exec()函数?使用shell_exec调用mv命令。
<?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);
}
?>
我从学院里找到的方法。
$src-源文件夹,$dst-目标文件夹。