Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to be notified as soon as a file is modified/changed?

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
This is my problem, I've been writing a utility to help automatically save replays of Ghost Recon, this is for dedicated servers, the thing is that Ghost Recon itself does not provide an option for this but I have noticed as soon as the game is over and Ghost Recon stops logging games another file is modified to contain the final scores of all players which is then loaded by Ghost Recon to present to the players, I thought about making a thread that keeps loading it say about every 10 seconds (the after match minimum time is 15 seconds therefore 10 secs) and compare it to the previous load by for example:
Code:
if not (Memo1.Text = Memo2.Text) then blablabla

Is this a good way to do it or is there a better method?


[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
there are (shell)components (on torry) that can help here, I'm thinking of fishfilenotification.zip that fires an event when the contents of some directory changes, but I'm not real sure I got it from torry, might also be from DSP ;-)

HTH
TonHu
 
in Samples Palette you can find ShellChangeNotifier that fire every time a directory change. You can use it's OnChange event.
Giovanni Caramia
 
And take a look at FindFirstChangeNotification in the SDK.

May be intercepting the shell will not work for you; usually a programmatic file operation is not noticed by the shell.

Note: in your case (with the file changing only every 15 secs), check the file last modified time every 10 secs and open it if changed. A time stamp check every 10 secs is negligible resource-wise. Shell intercepting and FindFirstChangeNotification need a sizable programming overhead to work in the way you need and you will end checking the time stamp anyway (well... it is true you'll check only on need, not blindly every 10 secs... but the difference is not so great other than from a purist point of view).

HTH.

buho (A).

 
A simpler way might be to write an application.onidle event that uses Tsearchrec to examine the time stamp on the file.
Dont know if the overhead on this would cause a problem.
Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top