473,480 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Howto: Regex & FileSystemWatcher Filter

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 action.

I can't assign the regex to the filter though:

FileSystemWatcher fsw = new FileSystemWatcher ();
fsw.Filter = regex; // won't work
How can I accomplish this?

TIA

Jul 21 '05 #1
1 5860
If you read the docs it accepts only a string. You will have to get all
watch for all *.txt and then apply the regex to any file changes you are
notified of. For what you are doing a regex might be a little heavy for the
file name comparison.

Lloyd Sheen
"Shmulik" <sh*******@yahoo.com> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
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 action.

I can't assign the regex to the filter though:

FileSystemWatcher fsw = new FileSystemWatcher ();
fsw.Filter = regex; // won't work
How can I accomplish this?

TIA

Jul 21 '05 #2

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

Similar topics

0
2439
by: Peter Valdemar M?rch | last post by:
Hi, In short, how to modify selected tags/sections of a HTML file, using PHP as the "modifier"/filter? I would have thought this was a very common usage for PHP... I have a set of existing...
0
328
by: John | last post by:
Is there a way to watch more than 1 extension? The default filter is *.* (watch all files with an extension). How do I set it so I can have *.txt and *.dll monitor? Thanks
2
4728
by: Ian Frawley | last post by:
anyone know how to filter different file types ie .jpg .gif in FileSystemWatcher.Filter? Ian -- "Life should NOT be a journey to the grave with the intention of arriving safely in an...
1
327
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$",...
4
3582
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
3
9785
by: emailtonitin | last post by:
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...
4
4369
by: hooksie2 | last post by:
Hi, I am trying to use FileSystemWatcher to watch a log file which is written to via a 3rd party app and display the log in listbox on a form. The FileSystemWatch seems to work okay but I get...
0
1151
by: Wilson799799 | last post by:
Hello, I am searching for a way to match quotation marks (extended ascii characters 147 and 148) with a .net regex. I tried this regex += .... |" + System.Convert.ToChar(147) + "|" +...
4
2844
by: Twayne | last post by:
Hi, I've been playing with ' if(!filter_var($email, FILTER_VALIDATE_EMAIL)) ' on my server and it seems to be working 100%. Pretty handy. Any ideas where I could find a summary of the e-mail...
0
7051
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
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7054
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
7097
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...
1
6750
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...
0
5353
agi2029
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,...
0
4493
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...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
193
bsmnconsultancy
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...

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.