|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Detect Moving, Copying files.I found that I'm able to determine whether a file is in the process of
being moved or copied to a landing directory that I monitor. I figure this out by attempting to open the file for reading. If I try the open and get FileIOException I decide that the file is in transit. If there is no exception then the I decide move/copy is complete. My question is: is there a better way? I ask this because handling FileIOException seems a little too broad when what I really want is to figure out if the file is coming. I've tried checking the file size, last access, last write. This doesn't seem to work. The exception message tells me that the file is being used by another process. That narrows things down a bit, but can I be sure that message will not change. Can I be sure that another process has not locked the file and accidently left it in that state. I need to move on to other files if that's the case. Thanks for your thoughts. Do you know FileSystemWatcher ?
Use FileSystemWatcher to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. You can create a component to watch files on a local computer, a network drive, or a remote computer. Regards Nicolas Guinet <rwbea***@gmail.com> a écrit dans le message de news: 1159977602.602121.210***@k70g2000cwa.googlegroups.com... Show quote >I found that I'm able to determine whether a file is in the process of > being moved or copied to a landing directory that I monitor. I figure > this out by attempting to open the file for reading. If I try the open > and get FileIOException I decide that the file is in transit. If there > is no exception then the I decide move/copy is complete. > > > My question is: is there a better way? I ask this because handling > FileIOException seems a little too broad when what I really want is to > figure out if the file is coming. I've tried checking the file size, > last access, last write. This doesn't seem to work. The exception > message tells me that the file is being used by another process. That > narrows things down a bit, but can I be sure that message will not > change. Can I be sure that another process has not locked the file and > accidently left it in that state. I need to move on to other files if > that's the case. > > Thanks for your thoughts. > The answer is yes I have looked at that class. Does it have any
functionality for determining whether a file is in transit or not? I understand that it will notify me if a file arrives. That isn't what I'm interested in. I have found that on a move or copy I'm not able to determine if a given file is in transit. LastAccess, LastWrite, and FileSize don't give any clue as to whether the file has arrived or not. The only way I've found that lets me know is to catch an IOException when trying to open the file. Nicolas Guinet wrote: Show quote > Do you know FileSystemWatcher ? > > Use FileSystemWatcher to watch for changes in a specified directory. You can > watch for changes in files and subdirectories of the specified directory. > You can create a component to watch files on a local computer, a network > drive, or a remote computer. > > Regards > Nicolas Guinet > > <rwbea***@gmail.com> a écrit dans le message de news: > 1159977602.602121.210***@k70g2000cwa.googlegroups.com... > >I found that I'm able to determine whether a file is in the process of > > being moved or copied to a landing directory that I monitor. I figure > > this out by attempting to open the file for reading. If I try the open > > and get FileIOException I decide that the file is in transit. If there > > is no exception then the I decide move/copy is complete. > > > > > > My question is: is there a better way? I ask this because handling > > FileIOException seems a little too broad when what I really want is to > > figure out if the file is coming. I've tried checking the file size, > > last access, last write. This doesn't seem to work. The exception > > message tells me that the file is being used by another process. That > > narrows things down a bit, but can I be sure that message will not > > change. Can I be sure that another process has not locked the file and > > accidently left it in that state. I need to move on to other files if > > that's the case. > > > > Thanks for your thoughts. > > |
|||||||||||||||||||||||