hook into a file, read new content in real time

此生再无相见时 提交于 2019-12-12 15:35:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!