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 ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ravi PuriPosted Mar 8, 2006, 10:28 AM
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")
{
...
}
...
}
Anthony FraylingPosted Mar 8, 2006, 4:36 AM
Anthony