如何在PHP 5.2中剪切和复制包含文件的文件夹到另一个路径


How do I cut and copy a folder with files in it to another path in PHP 5.2?

文件夹路径为f1/f2/。f1和f2都是文件夹F2文件夹包含许多子文件夹,如ff0,ff1,ff2,ff3。F2还包含一个名为copy_folder的文件夹。(路径为f1/f2/copy_folder)。我需要剪切和复制ff0,ff1,ff2,ff3中的所有内容以及文件夹(ff0,ff1,ff2,ff3)到路径是f1/f2/copy_folder . I。E,经过所有的处理后,copy_folder应该分别包含ff0,ff1,ff2,ff3及其内容。同样应该从旧文件夹中删除。E从文件夹f2

实际上我在php 5.3中用函数做了这个"复制"。这是我的示例代码mkdir(f1.f2/copy_folder/ff0)//我在copy_folder里面创建了一个文件夹Copy (f1/f2/ff0/t1.exe,copy_folder/ff0)//将内容拷贝到copy_folder中的ff0取消链接(f1/f2/ff0)//删除旧文件夹ff0

我在php 5.3中这样做了。但是它在php 5.2.1中不起作用。有什么问题吗?我使用zend框架工作。我在数组中使用一些细节('$arrNewClosedIncidentsDetails')

              foreach($arrNewClosedIncidentsDetails as $arrNewClosedDet)    

{                           //iteration of closed incident details there by taking the old path

                $strOldPath = $config->paths->releaseattach.'/'.$arrNewClosedDet['strPatchPath'];  //taking the

旧路如果(is_dir (strOldPath美元))

{//如果文件是目录

$strNewFolderPath = $config->paths->closedreleaseattach.'/'.$arrNewClosedDet['strFolderName'];

//taking the new folder path to which old folder and sub files have to copied
                        mkdir($strNewFolderPath); 
                                                              //making the directory in new path (with old folder name)
                        chmod($strNewFolderPath, 0777);   
                                                      //giving permission to this created folder
                        $arrNewFolderRelatedFiles = scandir($strOldPath);  
                                    //scan all files from old folder 
                        foreach($arrNewFolderRelatedFiles as 

$objNewFolderRelatedFiles){//遍历旧文件夹中的所有文件

                            if($objNewFolderRelatedFiles != '.' && $objNewFolderRelatedFiles != '..') 

{

                                        //remove default dot elements,which will present as the first and second array value
                             if (copy($strOldPath.'/'.$objNewFolderRelatedFiles, $strNewFolderPath.'/'.$objNewFolderRelatedFiles)) { 

//将所有跟踪到的文件复制到新路径下创建的相应文件夹中chmod ($ strNewFolderPath。"/"。objNewFolderRelatedFiles 0777美元);//对新文件夹

中创建的所有文件赋予权限
                                      unlink($strOldPath.'/'.$objNewFolderRelatedFiles);                                               //delete the files from old folder 
                                 }
                                }
                        }
                         rmdir($strOldPath);                                                                                                //remove all old folders
                }
             }

Thanks in advance

可以使用rename函数。rename(old_dir_name, new_dir_name)。http://php.net/manual/en/function.rename.php