copy directory

captainkuro edited this page Jan 10, 2013 · 6 revisions
Clone this wiki locally

Copy a directory (and its contents) recursively. The best way to use this would be to extend the directory helper because it uses the directory_map method. Or, you could load the directory helper and whatever helper this function would be in.

 * Copy a whole Directory
 * Copy a directory recrusively ( all file and directories inside it )
 * @access    public
 * @param    string    path to source dir
 * @param    string    path to destination dir
 * @return    array
    function directory_copy($srcdir, $dstdir)
        //preparing the paths

        //creating the destination directory
        if(!is_dir($dstdir))mkdir($dstdir, 0777, true);
        //Mapping the directory

        foreach($dir_map as $object_key=>$object_value)
                copy($srcdir.'/'.$object_value,$dstdir.'/'.$object_value);//This is a File not a directory
                directory_copy($srcdir.'/'.$object_key,$dstdir.'/'.$object_key);//this is a directory