Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi
i need to copy a lot of image files (more that a thousand image, each of which is maximum 1 MB), which are stored on different machines on intranet, to a central NAS storage.
i will write a C# program for that..
what is the most efficient method to do the job? is (File.Copy) enough, or...?

This process will be a daily job,
and it's NOT JUST a copying process.. files have to be organized in a specific hierarchy and their information has to be updated in database, so i think synchronization applications won't work for me

Since i need to update file status on database, then i need to know when the copying process of the file is finished, and whether it succeeded or failed (in in general, sometimes files are corrupted for some reason when copying fails)

What I have tried:

i have tried File.Copy for little number of files.. but haven't tried it for a large number.
Posted
Updated 8-Nov-17 22:05pm
v2
Comments
phil.o 8-Nov-17 15:52pm    
Most efficient in which terms? Clearly your requirements go further the simple file copy: you have to get the source file, link it to its record in the database, categorize it on criteria we don't know, then copy it to its destination, maybe verify by a checksum it has not been altered in the process, then, if check has succeeded, delete the source file and update the database record with the new path.
File.Copy can do its job, but it's only a little part of the whole process.
nina4ever 9-Nov-17 3:50am    
you are right. it is a whole process, and what you mentioned is correct.
but in my question i am only concerned about efficiency of the (copying) itself, since i have a large number of files, and i need a way to make sure they have been copied correctly, without corruption for example, and of course i need to know when file copy has finished (as i recall, by File.Copy there is no notification when copy is finished)..
phil.o 9-Nov-17 4:16am    
If you want to have an idea of the progress of a copy operation, you can go for streams. You will find plenty of examples of file copy with streams using delegates to signal the current progress. File.Copy does not provide this feature.
nina4ever 9-Nov-17 5:33am    
thanks for your help. i will give it a try
nina4ever 9-Nov-17 5:40am    
i found these answers. are they good?

https://stackoverflow.com/questions/39591579/how-to-use-filestream-for-copying-files-in-c-sharp

https://stackoverflow.com/questions/3427185/using-filestream-classes-to-copy-files-why-does-output-not-match-input

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900