Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an event when a file is placed in a directory 2

Status
Not open for further replies.

damonh78

Programmer
Jul 28, 2005
44
IE
Hi,

Has anyone any ideas on how I can solve a problem I am working on. In my application users upload files to a directory and these files are then processed by the app. I am working on a way that my application will know that a new file has been placed in the directory and can then process it. Unfortunately all the processed files have to stay in the directory as well, so I cant just use a timer and process any file that is in the directory and then move them afterwards. I suppose I could keep a list of all the files that are in directory and check every file against this each time but that would be very time consuming. I cant think of any way to know if a file is new or not.

Any ideas would be most helpful,

damonh
 
Please see thread222-1097046. I am unable to find the original coded posted by strongm but the code that is there is his originally (as pointed out in the thread).
 
Sure. Try these threads with my examples of how to do this: thread222-719707 (non-blocking version) and Thread222-576673 (blocking version)
 
cheers guys thanks very much thats a great help.
 
I'd like to do somethine similar on a shared drive but theses routines won't work. Any suggestions????
 
>theses routines won't work

Erm ... they work against network drives on my corporate network - but they have to have been mapped ...
 
My drives are also mapped but I always get an error 'Invalid handle -1) when i call FindFirstChangeNotification(...). It works fine on my local drives.
 
Erm ... my code, as illustrated in the linked threads, doesn't use FindFirstChangeNotification ...
 
Sorry strongm, got confused between your app and mine. Mine returns -1 (from the above function), yours just stays in an infinite loop and doesn't notice any changes. The file system is NWFS.

Regards,
 
Well, all I can say is that it works fine here (and I've even tested the asynchronous version against a drive mapped over a WAN VPN). Be careful, though, my example code is an illustration of the technique rather than a full solution, and only provides feedback to the user if

a) a file is added to the folder we are watching AND
b) the file is called "test.txt"

so you'd need to modify it for your own purposes

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top