FileSystemwatcher Filter
I'm busy creating a app to monitor files on the HDD. My question is how do i specify multiple filter types. i.e. for the system to look out for all .txt and all .xml files ?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Anthony Frayling2 pointsPosted Mar 7, 2006, 11:36 PM EST
Anthony
Ravi Puri10 pointsPosted Mar 8, 2006, 5:28 AM EST
Rightly so, you probably want to perform a custom filter inside the appropriate handler and ignore completely the
FileSystemWatcher.Filter method:
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\";
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
private static void OnCreated(object source, FileSystemEventArgs e)
{
if (e.Name.Substring(e.Name.LastIndexOf('.')) == ".xml")
{
...
}
if (e.Name.Substring(e.Name.LastIndexOf('.')) == ".txt")
{
...
}
...
}