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
  • 20,745
  • 15
  • 72
  • 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
  • 386,424
  • 207
  • 554
  • 861
2

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

Adriano Varoli Piazza
  • 6,993
  • 5
  • 38
  • 49
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
  • 7,929
  • 1
  • 32
  • 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
  • 509,016
  • 97
  • 693
  • 791