FileSystemWatcher and Large Files

G

Guest

I am using the FileSystemWatcher to watch a folder for new file. The new files will be very large. The Created event is fired when the new file first appears in a folder. How do I know when the file system is actually finished writing the new file?
 
Y

Ying-Shen Yu[MSFT]

Hi Jeff,

Do you mean you would like to get a notification when the file was
completely written to the disk?

If I understand you correctly, IMO there is no good way to get this
notification. The underlying file system uses cache heavily, the data might
be still cached in file system cache even after a file was closed. So It's
hard to know when a file will be written to disk completely.

Why do you need this notification?

Thanks!
Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
T

Terry

I also had the same question.
I want to monitor for files sent to a folder and then either move them to
another folder or import them into a database.
However I don't want to do this unless I know the file is complete.

Terry
 
Y

Ying-Shen Yu[MSFT]

Hi,

One workaround is open the file with exclusive rights. If the operation
fails, then wait and try again. Otherwise you are ready to process the file.

Thanks.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
G

Guest

When the created event fires I try to rename the file. If the rename fails I use a timer to wait and I try again until the rename succedes. Then the rename event fires and that is where my actual code is. I just thought there might be a cleaner way to do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top