views:

194

answers:

5

I need to create a windows service that will monitor a directory for newly uploaded files. The files will be around 100K to 400K in size.

Is there a chance that my monitoring system will notice a new file, but the file hasn't completetly finished copying over? i.e. it is still streaming in and the EOF hasn't been written yet?

A: 

yes. With small files the risk is fairly low, but if you want to be certain have it check when it sees a file to make sure it's size stays stable over a second or two.

tloach
+5  A: 

Yes, there is a chance that this will happen. You should upload the file to a temporary directory first, then move it to the directory you're monitoring when the entire file is present on your file system.

Bill the Lizard
+2  A: 

Try reading the second tale here and the comments. Essentially, it's as Bill the Lizard said

Adriano Varoli Piazza
Thanks, I knew I had read that somewhere! :)
Bill the Lizard
+1  A: 

Check this answer to a previous question for code that helps with this situation:

http://stackoverflow.com/questions/50744/wait-until-file-is-unlocked-in-net#50800

Eric Z Beard
A: 

Are you using a FileSystemWatcher? I've only used this once, but I think you can configure the parameters to tell it what events you want to consider and set up separate handlers for each. I suspect that the FileSystemWatcher may not even notify you on file creation until the file has been closed, but I haven't tried it.

Note: this is .NET solution. If you're not using .NET, please disregard.

tvanfosson