I am facing a design issue in my code related to the
filesystemwatch er'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 filesystemwatch er class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatch er to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endsw ith("*.txt") || filename.endswi th("*.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 3 9790
Personally I would use one and a regex to do the filterring but perhaps
someone knows a better way.
Cheers,
Greg
<em**********@g mail.comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
>I am facing a design issue in my code related to the
filesystemwatch er'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 filesystemwatch er class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatch er to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endsw ith("*.txt") || filename.endswi th("*.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
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.GetExtensi on().ToLower() ... and it will be much smaller code.
I am facing a design issue in my code related to the
filesystemwatch er'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 filesystemwatch er class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatch er to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endsw ith("*.txt") || filename.endswi th("*.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.
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 filesystemwatch er 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.GetExtensi on().ToLower() ... and it will be much smaller code.
>I am facing a design issue in my code related to the
filesystemwatch er'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 filesystemwatch er class and hook all
of them to the same event handlers.
2. To use 1 instance of filesystemwatch er to listen to all files using
blank filter. And in the event handler sort out the files that I need.
for eg. If (filename.endsw ith("*.txt") || filename.endswi th("*.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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 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...
|
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$",
RegexOptions.IgnoreCase);
That is, is the file CurrentOneFile.txt, CurrentTwoFile.txt, etc. shows in
in the directory I'm watching, then I can take...
|
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 documentation states that if more
than one file is copied to the folder at the same time, a cache will queue
them up for processing, but when I drop 3 files...
|
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( (val&4)!=0 )
fsw.NotifyFilter = System.IO.NotifyFilters.Attributes;
|
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 copy another one in. Here is what my
code:
// other codes to get a list of files
while (morefiles)
{
| |
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
\\server\path\foo* and FSW_B uses a filter of \\server\path\bar*. Now FSW_A
is really looking for 2 files, foo1yyyymmdd and foo2yyyymmdd while...
|
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 logic layer(so far so good and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have...
|
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?
|
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 receive any errors, it is just that FileSystemWatcher doesn't see any files dropped in the folder. What could be wrong?
Thanks
Goran
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |