Recursive Copy of Directory

前端 未结 14 941
花落未央
花落未央 2020-12-08 15:14

On my old VPS I was using the following code to copy the files and directories within a directory to a new directory that was created after the user submitted their form.

相关标签:
14条回答
  • 2020-12-08 15:46

    This function copies folder recursivley very solid. I've copied it from the comments section on copy command of php.net

    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); 
    }
    
    0 讨论(0)
  • 2020-12-08 15:46

    Why not just ask the OS to take care of this?

    system("cp -r olddir newdir");
    

    Done.

    0 讨论(0)
提交回复
热议问题