PC Review


Reply
Thread Tools Rate Thread

FileSystemWatcher Class.. Filters?

 
 
Ryan Rogers
Guest
Posts: n/a
 
      5th Mar 2004
The FileSystemWatcher Class has a filter property where you can tell it what
files you want it to watch for. I need it to watch for *.p** and *.f**
files both and have tried giving the filter the following strings
"*.p**;*.f**" and "*.p**,*.f**" and Each one on its own. Only when I supply
each one on its own does it pick up anything. My way around this was to
just use an if statement in the event triggers to look at the filename there
and drop it if its not what I want. I'm wondering if there is a better way?
Do I have the filter String Syntax wrong?

Ryan Rogers


 
Reply With Quote
 
 
 
 
Jared Parsons [MSFT]
Guest
Posts: n/a
 
      5th Mar 2004
I think your main problem is your filter string is incorrect and you need to
create multiple FileSystemWatcher objects to achieve your goal. Here is
some sample code.

watcher1 = new FileSystemWatcher(Application.StartupPath);

watcher2 = new FileSystemWatcher(Application.StartupPath);

watcher1.Filter = "*.p*";

watcher2.Filter = "*.f*";

watcher1.EnableRaisingEvents = true;

watcher2.EnableRaisingEvents = true;

watcher1.Created += new FileSystemEventHandler(this.HandleFileCreatedEvent);

watcher2.Created += new FileSystemEventHandler(this.HandleFileCreatedEvent);

watcher1.Deleted += new FileSystemEventHandler(this.HandleFileDeletedEvent);

watcher2.Deleted += new FileSystemEventHandler(this.HandleFileDeletedEvent);


--
Jared Parsons [MSFT]
(E-Mail Removed)
This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

"Ryan Rogers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The FileSystemWatcher Class has a filter property where you can tell it

what
> files you want it to watch for. I need it to watch for *.p** and *.f**
> files both and have tried giving the filter the following strings
> "*.p**;*.f**" and "*.p**,*.f**" and Each one on its own. Only when I

supply
> each one on its own does it pick up anything. My way around this was to
> just use an if statement in the event triggers to look at the filename

there
> and drop it if its not what I want. I'm wondering if there is a better

way?
> Do I have the filter String Syntax wrong?
>
> Ryan Rogers
>
>



 
Reply With Quote
 
 
 
 
Ryan Rogers
Guest
Posts: n/a
 
      8th Mar 2004
That was another idea of mine however I have four servers to watch.. so that
means I have to create 8 fileSystemwatchers. Seems kind of silly when I can
just create four and use and If statement in my Event that triggers on file
creation which it does now. II was more just curious if One
FileSystemWatcher object can handle the filters. Thanks for the advice
though.

Ryan

"Jared Parsons [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I think your main problem is your filter string is incorrect and you need

to
> create multiple FileSystemWatcher objects to achieve your goal. Here is
> some sample code.
>
> watcher1 = new FileSystemWatcher(Application.StartupPath);
>
> watcher2 = new FileSystemWatcher(Application.StartupPath);
>
> watcher1.Filter = "*.p*";
>
> watcher2.Filter = "*.f*";
>
> watcher1.EnableRaisingEvents = true;
>
> watcher2.EnableRaisingEvents = true;
>
> watcher1.Created += new

FileSystemEventHandler(this.HandleFileCreatedEvent);
>
> watcher2.Created += new

FileSystemEventHandler(this.HandleFileCreatedEvent);
>
> watcher1.Deleted += new

FileSystemEventHandler(this.HandleFileDeletedEvent);
>
> watcher2.Deleted += new

FileSystemEventHandler(this.HandleFileDeletedEvent);
>
>
> --
> Jared Parsons [MSFT]
> (E-Mail Removed)
> This posting is provided "AS IS" with no warranties, and confers no

rights.
> OR if you wish to include a script sample in your post please add "Use of
> included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm"
>
> "Ryan Rogers" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > The FileSystemWatcher Class has a filter property where you can tell it

> what
> > files you want it to watch for. I need it to watch for *.p** and *.f**
> > files both and have tried giving the filter the following strings
> > "*.p**;*.f**" and "*.p**,*.f**" and Each one on its own. Only when I

> supply
> > each one on its own does it pick up anything. My way around this was to
> > just use an if statement in the event triggers to look at the filename

> there
> > and drop it if its not what I want. I'm wondering if there is a better

> way?
> > Do I have the filter String Syntax wrong?
> >
> > Ryan Rogers
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileSystemWatcher stops working Rob Oldfield Microsoft Access Form Coding 2 6th Apr 2005 06:11 PM
FileSystemWatcher internal buffer problem Cxw0106 Microsoft Dot NET Framework 1 7th Aug 2003 06:50 AM
FileSystemWatcher and SERVER resources Jerry Ham Microsoft Dot NET Framework 1 2nd Aug 2003 07:49 AM
Acting on file from FileSystemWatcher Jude Wong Microsoft Dot NET Framework 0 30th Jul 2003 05:09 PM
FileSystemWatcher - implementation detail Tim Microsoft Dot NET Framework 2 23rd Jul 2003 05:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 AM.