The below given code will help you monitor all .txt files inside a given folder. It will monitor all .txt file in the given folder and subfolders. For you , if you have to monitor all .txt files in "C" drive, then give the path for FileSystemWatcher accordingly and set the filter to "*.txt" (Filter = "*.txt";) and set IncludeSubdirectories = true. It will then fire method "Action" for the changes to any .txt files.
public static void Main(string[] arg)
{
FileSystemWatcher watcher = new FileSystemWatcher(@"C:\testFolder")
{
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastAccess |NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName,
Filter = "*.txt"
};
watcher.Changed += Action;
watcher.Created += Action;
watcher.Deleted += Action;
watcher.Renamed += Action;
watcher.EnableRaisingEvents = true;
Console.ReadLine();
}
public static void Action(object obj, FileSystemEventArgs fileInfo)
{
Console.WriteLine(fileInfo.FullPath.ToString() + fileInfo.ChangeType);
}