Monitoring Directory Activity

FileSystemWatcher is a useful class for monitoring events that occur on a file or within a directory. This class invokes certain events whenever the directory or file is created, modified, renamed, or deleted. You provide the event handlers that occur when one of these events is raised. Listing 12.9 is a simple application that demonstrates capturing these events and outputting the type of change to the user.

Listing 12.9. FileSystemWatcher Example
1: unit WinForm1; 2: 3: interface 4: 5: uses 6: System.Drawing, System.Collections, System.ComponentModel, 7: System.Windows.Forms, System.Data, System.IO; 8: 9: type 10: TWinForm1 = class(System.Windows.Forms.Form) 11: private 12: { Private Declarations } 13: procedure ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.