Last year, I had the same need, and I tried Iztok Kachin: http://www.cromis.net/blog/downloads/directory-watch/ . He answered the email and helped a lot to answer my questions.
Its code worked, but I needed to get a notification at the moment when the file in a certain folder was closed, which for some odd reason, the ReadDirectoryChanges API (on which it depends) does not provide Microsoft (insanely). It also seems to me that Iztok code used streams and did not feel light enough for my needs.
In the end, I used a surprisingly simple approach that worked fine for me. At the TTimer event, which fires every few seconds, I use FindFirst in the folder that I control. All found files are placed in a constant TStringList. A new file that was not found in the StringList from previous TTimer events is new. (To determine if a file is closed, I try to open the file in exclusive mode. If I cannot open it, it will not be added to the TStringList so that it checks the next event.)
I rather did not dare to use this approach, thinking that it was too brute force. But for the needs that I had, this solution turned out great and, fortunately, is associated with a small amount of very simple code that is easy to understand and maintain.
Hth
RobertFrank
source share