Page 1 of 1

Watching several directories

Posted: Mon Dec 12, 2005 7:21 am
by Muesli
Hi again,

as I descripted in another thread, I write a program that does some jobs defined in template files. With your madShell my programm is notified when a new template file in the applications directory is created, so that this can be processed directly.
In some other folders there are textfiles, which includes data that has to be imported in another program. The path to this files are defined in some job templates. Now I also wanted to be informed when some new files are created in these folders.

So I defined an array of my own class which handles your madShell.

Code: Select all

fDirectoryWatches: Array Of TDirectoryWatch;
I have a method, that creates a new instance of this object and puts it in this array:

Code: Select all

procedure TNavPort.AddDirectoryWatch(Path: String);
  Idx: Integer;
    If Not DirectoryExists (Path) Then
    Path := IncludeTrailingPathDelimiter (Path);
    If PathIsAlreadyBeWatched (Path) Then

    SetLength (fDirectoryWatches, Length (fDirectoryWatches) + 1);

    //Creating a new instance: 
    //Seconds parameter defines whether subdirectories have to be monitored
    fDirectoryWatches[High (fDirectoryWatches)] := TDirectoryWatch.Create (Path, False);
    fDirectoryWatches[High (fDirectoryWatches)].OnFileCreated := DirectoryWatchFileCreated;

In my test the program has to watch two different folders:
1: D:\Sandbox\NavImport\Bin
2: D:\Sandbox\NavImport\Src
When I create a new file in directory 1, the notification is successful.
When I create a new file in directory 2, no notification has been done.
When I delete the file in directory 1, my program is being notified about the change, but then my windows explorer is blocked until my program is closed.

Isn't your madShell being constructed for multiple watches or have I made a mistake?


Posted: Thu Jan 05, 2006 10:36 am
by madshi
The problem is that the current build of madShell doesn't allow one event handler to be used for two different watch tasks. I've now changed that, so with the next build it should work. I've had no problems with the explorer here, though. That must be something different.

Posted: Thu Jan 05, 2006 12:34 pm
by madshi
The latest build is available here: