Re: Getting file names "on the fly" with XP?
- From: "Sven Abels" <dump2@xxxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 00:39:46 +0200
> The Win API has FindFirstChangeNotification, FindNextChangeNotification
> and
> WaitForSingleObject which can be used for this type of work. They are not
> limited to XP.
Thanks a lot for the tip!
I was able to find a TDirectoryWatch component at
http://www.angusj.com/delphi/
which actually looks quite good.
However: I cannot see a way of retrieving the actual file name / directory
name
that changed.
In the component, I think that it's somewhere in the following method but
I have no clue how to extract the file name:
procedure TWatchThread.ProcessFilenameChanges;
var
WaitResult : DWORD;
HandleArray : array[0..1] of THandle;
const
TEN_MSECS = 10;
HUNDRED_MSECS = 100;
begin
HandleArray[0] := fBreakEvent;
HandleArray[1] := fChangeNotify;
//INNER LOOP -
// exits loop if the directory is changed (or terminated).
// Any file changes will be processed within this loop
while (not Terminated) do
begin
//wait for either filename or directory change, or terminate...
WaitResult := WaitForMultipleObjects(2, @HandleArray, False, INFINITE);
if (WaitResult = WAIT_OBJECT_0 + 1) then //fChangeNotify event
begin
repeat //skip all (almost) immediate filename changes...
FindNextChangeNotification(fChangeNotify);
until Terminated or
(WaitForSingleObject(fChangeNotify, TEN_MSECS) <> WAIT_OBJECT_0);
if Terminated then break;
//OK, now notify the main thread (before restarting inner loop)...
PostMessage(fOwnerHdl, NOTIFYCHANGE_MESSAGE, 0, 0);
end else //fBreakEvent ...
begin // either directory changed or terminated ...
//skip all (almost) immediate directory changes before exiting...
while (not Terminated) and
(WaitForSingleObject(fBreakEvent, HUNDRED_MSECS) = WAIT_OBJECT_0)
do;
break;
end;
end;
end;
:-(
Best grettings,
Sven
.
- Follow-Ups:
- Re: Getting file names "on the fly" with XP?
- From: Stephen Posey
- Re: Getting file names "on the fly" with XP?
- References:
- Getting file names "on the fly" with XP?
- From: Sven Abels
- Re: Getting file names "on the fly" with XP?
- From: Bruce Roberts
- Getting file names "on the fly" with XP?
- Prev by Date: Re: Getting file names "on the fly" with XP?
- Next by Date: Re: Getting file names "on the fly" with XP?
- Previous by thread: Re: Getting file names "on the fly" with XP?
- Next by thread: Re: Getting file names "on the fly" with XP?
- Index(es):
Relevant Pages
|