Re: Getting file names "on the fly" with XP?





> 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


.



Relevant Pages

  • Re: Safe multithreading in ASP.Net
    ... Why is your thread running in this endless loop? ... > will reach the end of it's code and it will terminate. ... > the thread still continues to execute. ... > goal of this thread is to send emails. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Program analysis
    ... known if a program will ever terminate. ... an effect on the loop condition. ... would/would not terminate you might have resolved FLT without all the 'fancy ... the Halting Problem is about programs in general: ...
    (comp.programming)
  • Re: A Good Use of End
    ... I know it isn't "the done thing" for example to write code that runs in a loop when a Timer would be more suitable, but many people do it, especially when writing applications that produce animated graphic output of some sort and it is a fairly commonly accepted practice. ... Private Sub Command1_Click ... If you click Command1 to start the loop and then click Command2 while the loop is running then on most systems the program will not actually finish. ... If ytou're running it as a compiled exe it will certainly *appear to terminate*, but it'll still be hanging on in there if you look at the lost of running apps. ...
    (comp.lang.basic.visual.misc)
  • Re: Ada and (SIGTERM?)
    ... signal and terminate gracefully: did you look at RM C.3? ... me you could set up an interrupt handler to catch SIGTERM and have it ... the variable), then instead of an "infinite" loop, make the loop ... could set a Boolean in the protected object that controls a protected ...
    (comp.lang.ada)
  • Re: Any way to force an iteration in a For Each loop?
    ... >Is there some way to terminate one iteration in a For Each loop ... >For Each obChar In Selection.Characters ... If obChar.Text = "A" Then GoTo SkipIt ...
    (microsoft.public.word.vba.general)