FileSystemWatcher Class.. Filters?

Discussion in 'Microsoft Dot NET' started by Ryan Rogers, Mar 5, 2004.

  1. Ryan Rogers

    Ryan Rogers Guest

    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
     
    Ryan Rogers, Mar 5, 2004
    #1
    1. Advertisements

  2. 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]

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Jared Parsons [MSFT], Mar 5, 2004
    #2
    1. Advertisements

  3. Ryan Rogers

    Ryan Rogers Guest

    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]" <> wrote in message
    news:...
    > 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]
    >
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    Ryan Rogers, Mar 8, 2004
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Ryan
    Replies:
    0
    Views:
    501
    William Ryan
    Jun 29, 2003
  2. Yan-Hong Huang[MSFT]
    Replies:
    0
    Views:
    444
    Yan-Hong Huang[MSFT]
    Jul 1, 2003
  3. A.S.

    FileSystemWatcher gives invalid path error

    A.S., Jul 18, 2003, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    735
  4. Josh Usovsky

    Using FileSystemWatcher with large files

    Josh Usovsky, Jul 25, 2003, in forum: Microsoft Dot NET
    Replies:
    5
    Views:
    508
  5. Shawn Wilson via .NET 247

    FileSystemWatcher Class - File Access

    Shawn Wilson via .NET 247, Apr 26, 2004, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    227
    Shawn Wilson via .NET 247
    Apr 26, 2004
Loading...

Share This Page