Skip to content

Wosi/DirectoryWatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DirectoryWatcher

Watch changes in directories on different platforms.

This is an abstraction layer for

  • ReadDirectoryChangesW on Windows
  • FSEvent on Mac OS
  • inotify on Linux

How to use

// Create new DirectoryWatcher
DirectoryWatcher := TDirectoryWatcherBuilder
                    .New
                    .WatchDirectory(FolderToWatch)
                    .Recursively(True)
                    .OnChangeTrigger(OnFileEvent)
                    .Build;

// Start watching in different thread
DirectoryWatcher.Start;

// Stop DirectoryWatcher
DirectoryWatcher := Nil;

// ...

procedure TDirectoryWatcherDemo.OnFileEvent(const FilePath: String; 
                                            const EventType: TDirectoryEventType);
var
  EventTypeString: String;
begin
  WriteLn('======NEW EVENT======');
  WriteLn('File: ' + FilePath);

  case EventType of
    detAdded: EventTypeString := 'ADDED';
    detRemoved: EventTypeString := 'REMOVED';
    detModified: EventTypeString := 'MODIFIED';
  end;

  WriteLn('Type: ' + EventTypeString);
end;  

Releases

No releases published

Packages

No packages published

Languages