Board index » delphi » API for reporting changes in directory or file???

API for reporting changes in directory or file???

I know there should be a API function in Win32 that can be used to
alert an application when there has been a change in a directory or in
a file. I can't find it so i would be happy if someone can tell me
which API and also give an example code snippet.
I am using D5 and I want to tell when a file has been created in a
directory and when a special file has been changed. The first task I
can do with a loop like below but it turns out to use up 100% of the
CPU cycles, so it is not good.

while not FileExists(sMyWatchFile) do
  Application.Processmessages;

If I use a timer I can reduce the cycle usage, but then there will not
be a quick response when the file is created....

Bo Berglund
bo.bergl...@telia.com

 

Re:API for reporting changes in directory or file???


Quote
"Bo Berglund" <bo.bergl...@telia.com> wrote in message

news:3be25068.2711497377@news.telia.net...

Quote
> I know there should be a API function in Win32 that can be used to
> alert an application when there has been a change in a directory or in
> a file. I can't find it so i would be happy if someone can tell me
> which API and also give an example code snippet.
> I am using D5 and I want to tell when a file has been created in a
> directory and when a special file has been changed. The first task I
> can do with a loop like below but it turns out to use up 100% of the
> CPU cycles, so it is not good.

> while not FileExists(sMyWatchFile) do
>   Application.Processmessages;

> If I use a timer I can reduce the cycle usage, but then there will not
> be a quick response when the file is created....

FindFirstChangeNotification and FindNextChangeNotification can be used with
WaitForSingleObject and WaitForMultipleObjects. All of these calls are
documented in the Win SDK help. IIRC there is also ReadDirectoryChangesW
that may be of use, however it is not available in W95/98.

Other Threads