473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

design to overcome filesystemwatcher filter limitation

I am facing a design issue in my code related to the
filesystemwatcher's filter property.
I figured out that the filter won't accept multiple patterns for eg.
"*.txt, *.csv" don't work.

To workaround this issue, I have 2 options:
1. To create multiple instances of filesystemwatcher class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatcher to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endswith("*.txt") || filename.endswith("*.csv"))
//do stuff

My question is which approach is going to be more efficient, provided:
The list of file extensions that I need to watch are configurable (are
subject to change/number of extensions to be watched may go up)

Want to know your thoughts before deciding eitherway.
Thanks,
Nitin

Aug 1 '06 #1
3 9781
Personally I would use one and a regex to do the filterring but perhaps
someone knows a better way.

Cheers,

Greg
<em**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>I am facing a design issue in my code related to the
filesystemwatcher's filter property.
I figured out that the filter won't accept multiple patterns for eg.
"*.txt, *.csv" don't work.

To workaround this issue, I have 2 options:
1. To create multiple instances of filesystemwatcher class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatcher to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endswith("*.txt") || filename.endswith("*.csv"))
//do stuff

My question is which approach is going to be more efficient, provided:
The list of file extensions that I need to watch are configurable (are
subject to change/number of extensions to be watched may go up)

Want to know your thoughts before deciding eitherway.
Thanks,
Nitin

Aug 1 '06 #2
Greg Young wrote:
Personally I would use one and a regex to do the filterring but perhaps
someone knows a better way.
That's probably the best approach, imho. Multiple watchers means
multiple OS waits: it's definitely going to be more efficient to watch
a whole directory than to watch multiple patterns.

Regex isn't going to be much (if any) slower than looping through an
array of masks and comparing each mask to
Path.GetExtension().ToLower() ... and it will be much smaller code.
I am facing a design issue in my code related to the
filesystemwatcher's filter property.
I figured out that the filter won't accept multiple patterns for eg.
"*.txt, *.csv" don't work.

To workaround this issue, I have 2 options:
1. To create multiple instances of filesystemwatcher class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatcher to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endswith("*.txt") || filename.endswith("*.csv"))
//do stuff

My question is which approach is going to be more efficient, provided:
The list of file extensions that I need to watch are configurable (are
subject to change/number of extensions to be watched may go up)

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 1 '06 #3
Thanks guys.
Yes, using multiple watchers didn't seem right to me too.
Ok, I'll go the single watcher + regex way.

As a sidenote, the lack of support for multiple patterns in the filter
property of the filesystemwatcher seems more like an incomplete
functionality of the class, prevelant since framework version 1.1.
Lets hope that some future release takes care of it.

Jon Shemitz wrote:
Greg Young wrote:
Personally I would use one and a regex to do the filterring but perhaps
someone knows a better way.

That's probably the best approach, imho. Multiple watchers means
multiple OS waits: it's definitely going to be more efficient to watch
a whole directory than to watch multiple patterns.

Regex isn't going to be much (if any) slower than looping through an
array of masks and comparing each mask to
Path.GetExtension().ToLower() ... and it will be much smaller code.
>I am facing a design issue in my code related to the
filesystemwatcher's filter property.
I figured out that the filter won't accept multiple patterns for eg.
"*.txt, *.csv" don't work.
>
To workaround this issue, I have 2 options:
1. To create multiple instances of filesystemwatcher class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatcher to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endswith("*.txt") || filename.endswith("*.csv"))
//do stuff
>
My question is which approach is going to be more efficient, provided:
The list of file extensions that I need to watch are configurable (are
subject to change/number of extensions to be watched may go up)


--

.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ryan Rogers | last post by:
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...
1
by: Shmulik | last post by:
How can I (can I?) use a regular expression as the filter to a FileSystemWatcher? I want to watch for something like this: Regex regex = new Regex(@"^Current(One|Two|Three)File\.txt$",...
1
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the...
1
by: eyal | last post by:
Hi, I'm trying to do this: private void SetNF(FileSystemWatcher fsw,int val){ if( (val&4)!=0 ) fsw.NotifyFilter |= System.IO.NotifyFilters.Attributes; // i'v tried this also: // if(...
2
by: John Lee | last post by:
Hi, I wrote a small program that copy a list of files to a specified folder one by one, i.e. this app will copy one file into the specified folder and wait until it's consumed (deleted) then...
0
by: Eric Wong | last post by:
I am experiencing a bizarre problem using FileSystemWatcher... I have an application that uses multiple FileSystemWatcher to watch for particular files on a network drive. FSW_A uses a filter of...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
12
by: ljh | last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event twice when a file is changed? Do you have any idea why this is the case?
5
by: Goran Djuranovic | last post by:
Hi all, I have a file system watcher service that works fine on a local hard drive, but will not work across the network. I tried both: mapping the drive and "\\..." path both no luck. I don't...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.