4

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?

hikari
  • 3,393
  • 1
  • 33
  • 72

2 Answers2

3

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?

Community
  • 1
  • 1
Nat
  • 5,414
  • 26
  • 38
2

Kinda similar to this: Monitor files similar to System Internal's/Microsoft's FileMon/Process Monitor

Community
  • 1
  • 1
Chris Thornton
  • 15,620
  • 5
  • 37
  • 62