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?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
  • 2
    Please state the language you wish to develop it in as this changes how your question is answered. –  Oct 08 '08 at 13:48

4 Answers4

5

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
  • 398,270
  • 210
  • 566
  • 880
2

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

Adriano Varoli Piazza
  • 7,297
  • 5
  • 39
  • 50
0

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
  • 8,009
  • 1
  • 33
  • 44
0

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
  • 524,688
  • 99
  • 697
  • 795