-
Apr 1st, 2013, 07:58 AM
#1
Thread Starter
Hyperactive Member
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,
-
Apr 1st, 2013, 09:10 AM
#2
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.
-
Apr 1st, 2013, 10:51 AM
#3
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?
-
Apr 1st, 2013, 11:19 AM
#4
Re: Copy files from one location to another given location
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.
-
Apr 1st, 2013, 11:23 AM
#5
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.
-
Apr 1st, 2013, 11:54 AM
#6
Thread Starter
Hyperactive Member
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.
-
Apr 1st, 2013, 11:58 AM
#7
Re: Copy files from one location to another given location
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|