473,406 Members | 2,356 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,406 software developers and data experts.

How to filter using filesystem watcher in vb.net

HI, I Want to filter a file using filesystem watcher. In that, I want to filter more than one type. Let it be, *.exe, *.java....... How can I achieve this
Dec 14 '09 #1
2 2334
tlhintoq
3,525 Expert 2GB
I'm reasonably certain you'll need to set up one FileSystemWatcher for each extension.

There should be no problem pointing them all to the same method handler if you need to. The arguments of the event include the file name, so you can use a Switch construct to take action dependent on the extension from there.
Dec 14 '09 #2
!NoItAll
297 100+
Maybe this is a stupid suggestion, but depending on what you are watching you could set the filter to *.* and then process only the files you want in the function - returning gracefully for any file that does not match your criteria.

This isn't practical if you are watching the entire file system, but if you are looking at a single folder and its subs then this is a reasonable approach.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Friend Sub MyTriggeredFunction(ByVal sFile as String)
  3. Static sExtensions() as String = {".txt", ".csv", ".doc"}
  4.  
  5. For each sExt as String in sExtensions
  6.  
  7.     If System.IO.Path.GetExtension(sFile).ToLower.Contains(sExt) then
  8.             'process the file
  9.             Return  
  10.     End if
  11.  
  12. Next sExt
  13.  
  14.  
This seems reasonable to me - but only if you are not watching the entire spectrum of files on a system.
Dec 19 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: timb | last post by:
Hi, i want to declare an array of file system watcher objects. The idea is that my config file specifies how many directories to monitor and then i dynamically declare the filesystemobjects and...
1
by: R.A. | last post by:
Hi I have a class which contains a datagrid and a file watcher object. When the file watcher event is triggered then in the event handler I add rows to the data grid. the problem is that every...
5
by: ToddT | last post by:
i've got one app that writes large files to a specific directory that is watched by another app via an instance of the file system watcher class. my problem is that the second app is notified when...
1
by: Stuart Ferguson | last post by:
I am currently writing a Windows service which monitors multiple folders and processes the files in them accordingly. The folders to be monitored are stored in a string array. I can think of 2...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
2
by: eric.goforth | last post by:
Hello, I'm using the Filesystemobject in VB.NET 1.1. Is there anyway to filter on the files based on an extension? Something like: Dim fso As New FileSystemObject Dim objFolder As Folder...
0
by: Tedmond | last post by:
Dear all, I need to write a watchdog program to monitor several services. Restart the services if they are stopped by any reason. I got a sample code as follows watcher = new...
3
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...
6
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project...
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: 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
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
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
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
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...
0
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,...

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.