forked from bcit-ci/CodeIgniter
-
Notifications
You must be signed in to change notification settings - Fork 0
copy directory
Derek Jones edited this page Jul 5, 2012
·
3 revisions
My first contribution :).... My function to copy all directory's content, use it as you want but the best way would be to include it in the directory helper because it uses directory_map function or to load both 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
*/
if(!function_exists('directory_copy'))
{
function directory_copy($srcdir, $dstdir)
{
//preparing the paths
$srcdir=rtrim($srcdir,'/');
$dstdir=rtrim($dstdir,'/');
//creating the destenation directory
if(!is_dir($dstdir))mkdir($dstdir);
//Mapping the directory
$dir_map=directory_map($srcdir);
foreach($dir_map as $object_key=>$object_value)
{
if(is_numeric($object_key))
copy($srcdir.'/'.$object_value,$dstdir.'/'.$object_value);//This is a File not a directory
else
directory_copy($srcdir.'/'.$object_key,$dstdir.'/'.$object_key);//this is a dirctory
}
}
}