Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the simplest way to monitor for changes to a single file?

Should I look at shell notifications? Is there a good free component, or some example source code?

Or should I just start a one second timer and check the file's timestamp periodically?

It doesn't have to be elegant, just the simplest that will work. I am more interested in the processing which I will do when the file changes (it's a log file, whenever it gets updated I want to parse it and show some details of the test run).

like image 463
Mawg says reinstate Monica Avatar asked Sep 02 '25 17:09

Mawg says reinstate Monica


2 Answers

Shell notifications are nice, but more complex than a timer. If a one second polling interval is good enough, you could use that.

But you can build a 'Monitor' yourself, which encapsulates the actual monitoring code. This Monitor raises an event if the file is changed. That monitor of yours can encapsulate a timer at first (easy, two minute job), but can be modified to use shell notifications later (better), without having to modify all your application logic.

like image 111
GolezTrol Avatar answered Sep 05 '25 14:09

GolezTrol


Jedi VCL inherits change-notification/folder-monitor from RxLib.
RxLib also might be available for older versions of Delphi

BTW, you did not specify you Delphi version. Please, press RETAG link and add the proper tag.

like image 25
Arioch 'The Avatar answered Sep 05 '25 15:09

Arioch 'The