 |
Experts on Demand
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?
QUESTION POSED ON: 13 JAN 2005
QUESTION ANSWERED BY: Daniel Cazzulino
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.
|
 |
|
|
 |
 |
 |
 |
| TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of . |
|
| |
All Rights Reserved, , TechTarget |
|
|
|
|
|