I'm just using trial and error with the madshell RegisterShellEvent command. I am getting strange and inconsistent results:
If you use Explorer to add and delete files to an UNWATCHED folder, you will get double events and the event will be Item Created and Item Deleted.
If you use an exe that writes and deletes the file, you will get a Dir Changed event for each instead!.
If you delete a file in an UNWATCHED folder, the ojb1 object does not exist and you will get an exception trying to set it to a string. Instead,
the function returns INFO2.
If you are WATCHING a folder, and use any method to create a file in the watched folder, the events are Item Created and Item Deleted. If I try to write to the file, I get 2 Item Changed events.
If I create the file in notepad and do a file -> save as I get 2 Item Created events
I also have an issue where I have to delay the "Reset" command to open the file that I am watching for because the event arrives before the file is completely closed by the other application. I am getting Error 32 errors.
Does anyone have some hints at how to use this for something simple, like just watching a folder for a file to appear, then getting the info from it and delting it? Are there tricks for which event to watch for and how to do this? I am currently using "Item Created", but if someone uses some other method of putting the file in the folder other than a normal file write (like using explorer or writing from word) I would have to have completely different logic.
Also, any ideas about how to get around the file in use issue? So far a 20ms delay in between getting the Item Created event and running code in that event handler to Reset the file seems to work. But I was wondering about having a retry of 3 or 4 times over so many clock ticks. Thanks!
About the "in use" problem: If you listen for the "create" event, of course there's no way to know for sure how much time it will need for the file to be closed again. One application might just create, write and close in one go. Another application might keep the file open for a while. You may have to implement a timer that retries opening new files every 100ms (or so) until you succeeded. For that to work you'd have to store all created files in an internal list, of course.