copy directory

A

Anonymous

Guest
Hello,

I would like to copy a folder, subfoders and all the files in it with the copy command. Does anyone know how to do this or have any example they can provide?

Thanks
 
You can use PHP's copy() function or even running the appropriate command with exec() function or equivalent.
You have a few great examples at the copy() manual section (above).
 
Hi,

I have created a function to delete folders and sub folders with file.

Please try with this function and modify this code to copy.
remove @unlink($dir.'/'.$file); and put copy file/folder syntex....!

I thinks this ill help you.

Code:
function unlink_dir($dir)
{
	$handle = @opendir($dir);
	while (false!==($file= @readdir($handle)))
	{
		if($file != '.' && $file != '..')
		{
			if(is_dir($dir.'/'.$file)) 
			{
				unlink_dir($dir.'/'.$file);
			}
			else
			{
				@unlink($dir.'/'.$file);
			}
		}
	}
	@closedir($handle);
	
	if(@rmdir($dir))
	{
		$success = true;
	}
return $success;
}

set the variable as given in example and call the function

$delete_dir_name = "temp";


if(!unlink_dir($delete_dir_name))
print "There is no such dir or file";
else
print "All Sub Dir and files are deleted";
 
Back
Top