问题
How would I hook into a file that's currently in use by another program, which constantly writes out to it? Let's say, there's a text file with 10 lines. When I start my app it has to detect and read any content from there on everytime the writing program saves its content. Can this be done without a constant check on the filesize/date?
回答1:
You could monitor the folder for changes using the ReadDirectoryChangesW API.
Keep track of the last position you read to, and when you receive a change notification for that file, read from there to the end of the file (as it currently stands).
An example of how to use the ReadDirectoryChangesW API is here:
Why does ReadDirectoryChangesW omit events?
回答2:
Kinda similar to this: Monitor files similar to System Internal's/Microsoft's FileMon/Process Monitor
来源:https://stackoverflow.com/questions/6427636/hook-into-a-file-read-new-content-in-real-time