Copy files from one location to another given location
Hi,
How to copy all files from one folder to another folder and also rename of all files in destination folder
Thanks,
Re: Copy files from one location to another given location
Directory.GetFiles will give you an array containing the path of all files in a folder. You can loop through that and call File.Copy for each one. You can transform the file name however is appropriate. Path.GetFileName and .GetFileNameWithoutExtension might be handy in getting the original file name as a source for that transformation.
Re: Copy files from one location to another given location
Doesn't GetFiles call the API FindFirstFile which dates back to around Windows 2000. Wouldn't EnumerateFiles() be a better solution?
Re: Copy files from one location to another given location
Quote:
Originally Posted by
ident
Doesn't GetFiles call the API FindFirstFile which dates back to around Windows 2000. Wouldn't EnumerateFiles() be a better solution?
Unless you're dealing with a large number of files, it will make no significant difference. If you're using .NET 4.0 or later though, using EnumerateFiles will not hurt.
Re: Copy files from one location to another given location
I wouldn't expect there to be any performance difference. Just appears to fit better.
Re: Copy files from one location to another given location
Copy file from one location to another can be done using file.copy but problem is while copy rename the file too.
Re: Copy files from one location to another given location
Quote:
Originally Posted by
asm
Copy file from one location to another can be done using file.copy but problem is while copy rename the file too.
When you call File.Copy you have to specify the destination file path. If you want the name destination name to be different to the source name then you use a different name in the destination path to the source path. I already addressed that in my first reply.