I have a project that is watching a folder for new files. The FileSystemWatcher notifies us when a new file has arrived, but I have to wait until the file has completed its copy before continuing the program. Currently I use a time to wait routine and guess the duration based on its size. Is there any method that can be used to determine when the file has finished copying (which is usually across the LAN)? The OS will let me manipulate the file info (e.g., comparing the files length, name, path and so on), but I have to wait until the file copy is complete to continue processing. Any thoughts?
The FileSystemWatcher provides two events you can use in your scenario: Created and Changed. The former is of little use since you need to know when the entire file has finished copying. The later is the one to look for. You will get two calls to that event during a lengthy copy. You get one when the file is created, because the initial attributes of the file are changed (such as the last write attribute). The second call to this event is the one you're interested in, as it's done after copying finished, to set the last modified date and last access time attributes on the file. So you will have to keep a flag so you skip the first event call, and react to the second one.
This Content Component encountered an error
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.