Directory watch class, that can monitor the selected directory included with sub-directories. Main features:
- Simple to use class, that enables you to watch for all changes in a given directory
- Watch only the selected directory or also all its sub-directories
- You can define exactly what notifications you will receive
The demo bellow shows the basic usage of DirectoryWatch. If you have trouble using the code or have any other questions, please contact me directly using the “Contact” page.
procedure TfMain.btnStartClick(Sender: TObject); begin FDirectoryWatch.WatchSubTree := cbWatchSubdirectories.Checked; FDirectoryWatch.Directory := eDirectoryName.Text; FDirectoryWatch.Start; btnStart.Enabled := False; btnStop.Enabled := True; end;
procedure TfMain.OnNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string); var ListItem: TListItem; begin lvWatchActions.Items.BeginUpdate; try ListItem := lvWatchActions.Items.Add; ListItem.Caption := GetEnumName(TypeInfo(TWatchAction), Integer(Action)) ; ListItem.SubItems.Add(FileName); finally lvWatchActions.Items.EndUpdate; end; end;
- Added buffer size property, so that the user can control the size of buffer
- Added OnError event handler, so user get notified of all errors
- Check the result of ReadDirectoryChangesW with GetOverlappedResult. This way we can check if buffer overflow happens and trigger an error.
- Close the FChangeEvent handle
- WaitForFileReady added. Waits until file is free to be used
- 64 bit compiler compatible
- Fixed thread termination bug
- Refactored the main watch loop
- Initial code rewrite from “FnugryDirWatch”