473,698 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to filter using filesystem watcher in vb.net

92 New Member
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 2347
tlhintoq
3,525 Recognized Expert Specialist
I'm reasonably certain you'll need to set up one FileSystemWatch er 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 Contributor
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
1347
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 add them to an array. This idea was so i can create a event for handling these events since i dont know how many there are at design time and therefore cannot create the stub code. Does anyone have any examples of such use of arrays?
1
1204
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 time I add rows to the datagrid from the file watcher event handler the program stops - there are no exceptions thrown the program just terminates. I have checked the datagrid without adding rows in the file watcher handler and there are no...
5
2018
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 files are created, but the first app hasn't finished writing to it - causing a "file is already open" error when the second app trys to open the file for processing. what i need is a "file closed" event to be thrown by the file system watcher...
1
3465
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 ways of determining which folder has had the file dropped into it and was wondering if there was a better way. The 2 solutions i have are as follows. 1) When the file is picked up by the OnChanged event search the array to determine the file...
2
11407
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, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use managed code instead. I couldn't find any easy way of doing this but searching the Internet with...
2
10839
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 Dim objFile As File 'Work with the root first
0
2240
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 ManagementEventWatcher("SELECT * FROM __InstanceOperationEvent WITHIN 4 WHERE TargetInstance ISA 'Win32_Service' AND Targetinstance.Name = 'MyService' AND TargetInstance.State= 'Stopped'"); watcher.EventArrived += new
3
9800
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 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...
6
17017
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 as "Additional Dependencies" under Linker-Input options. Since those libraries are also in different directory, I specified that library path in project as "Additional Library Directories" under Linker-General options. This is where I see some...
0
8600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9155
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9018
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8858
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4360
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.