tags:

views:

412

answers:

5

What is the best way to go about monitoring a folder to see when an image file has been added to it? Files are added approximately once a minute and the naming goes like this... image0001.jpg, image0002.jpg, image0003.jpg etc. I need to know when a file has been written to the folder so that my app can access and use it.

+8  A: 

Look into directory change notifications.

Ferruccio
A: 

inotify might be your thing

John Nilsson
Inotify is Linux-only, unfortunately.
JesperE
Hmm. I was under the impression that the librarys were ported to different platforms.
John Nilsson
+1  A: 

FileSystemWatcher should be able to do that for you.

Aaron Smith
A: 

As per previously mentioned, the directory change notifications is what you want.

I have looked into them as well, and the caveat I have seen is that windows will fire off the notification when the file starts to be written to the folder. If the file is large enough then you will receive the notification before the file has finished being written.

Check out this google search for various solutions for waiting until the file is completely written

Edit: I just saw that the question was tagged with c++, and I linked to a .Net search. Although what I provided may not be the correct language, I would think that you will still have the same issues on Windows no matter what system you are coding with.

Peter M
+1  A: 

Change notifactions may cause some overhead, if you've NTFS, consider NTFS change journals.

yrp