Watching several directories
Posted: 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.
I have a method, that creates a new instance of this object and puts it in this array:
In my test the program has to watch two different folders:
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?
Greetings,
Muesli
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;
Code: Select all
procedure TNavPort.AddDirectoryWatch(Path: String);
Var
Idx: Integer;
begin
fCriticalSection.Enter;
Try
If Not DirectoryExists (Path) Then
Exit;
Path := IncludeTrailingPathDelimiter (Path);
If PathIsAlreadyBeWatched (Path) Then
Exit;
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;
Finally
fCriticalSection.Leave;
End;
end;
In my test the program has to watch two different folders:
When I create a new file in directory 1, the notification is successful.1: D:\Sandbox\NavImport\Bin
2: D:\Sandbox\NavImport\Src
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?
Greetings,
Muesli