Watching several directories

delphi package - easy access to shell apis

Watching several directories

Postby Muesli » Mon Dec 12, 2005 7:21 am

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?

Posts: 3
Joined: Mon Dec 12, 2005 6:04 am

Postby madshi » Thu Jan 05, 2006 10:36 am

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.
Site Admin
Posts: 9591
Joined: Sun Mar 21, 2004 5:25 pm

Postby madshi » Thu Jan 05, 2006 12:34 pm

The latest build is available here:
Site Admin
Posts: 9591
Joined: Sun Mar 21, 2004 5:25 pm

Return to madShell

Who is online

Users browsing this forum: No registered users and 1 guest