473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File System Watcher Usage

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 type (by matching the path the file is in against a
path in the file profile)

2) Create a different event for each file profile (folder being
monitored) and then process accordingly.

I need the application to be easily scalable thus option 2 isnt the best
for me as code changes would be needed for the new file profile which i
am trying to avoid.

If anyone has any better methods they would be appreciated.

Thanks,

Stuart Ferguson

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
1 3463
Hi,
On the contrary I think that the solution 2 is the best for you, create a
collection of FileSystemWatch ers and point each one to the directory you
want. if all of them use the same event handler to process the OnChanged
events it;s easier, otherwise it gets more complex

like this:

//member variable
ArrayList watchers= new ArrayList();

void CreateWatchers( )
{
foreach( string dir in DirectoryArray)
{
FileSystemWatch er watcher = new FileSystemWatch er ();
watcher.Path = dir;
...
watcher.OnChang ed = new ....
watchers.Add( watcher);
}
}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Stuart Ferguson" <st************ **@btinternet.c om> wrote in message
news:OI******** ********@TK2MSF TNGP15.phx.gbl. ..
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 type (by matching the path the file is in against a
path in the file profile)

2) Create a different event for each file profile (folder being
monitored) and then process accordingly.

I need the application to be easily scalable thus option 2 isnt the best
for me as code changes would be needed for the new file profile which i
am trying to avoid.

If anyone has any better methods they would be appreciated.

Thanks,

Stuart Ferguson

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

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

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
3
4135
by: Ron Vecchi | last post by:
Hi all, Can someone point me in the direction on this one, resources or examples. I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders it should write the name of the file to a xml file. Then at a specifed time all the files in the xml quene will be backed up on a network share. ...
7
4109
by: Allen Anderson | last post by:
I'm trying to figure out a way to catch when a file has been written to a directory. I currently have it where I can catch when the file begins writing, but this isn't helpful as I need to know when its done. Does anyone know the right combination of flags to use to catch when the file has been written and closed? (here is my current code)....
0
2562
by: Jack David | last post by:
I am using the following code to monitor a directory for new files. The problem is that when I add a new file to the directory the code creates two events??? what do I have to do to limit it to only one event?? using System; using System.IO; namespace DirectoryWatcher
2
3302
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor a couple of different directories and based upon the directory where the new file is created kick-off a process Example: File A in Directory B...
5
2016
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...
17
2689
by: spentun | last post by:
How can I moitor file which is executed by user or program in window. I need to write a code to monitor file. When user clicks the file(.exe) or is called by program, the name of file will be return to a program. so, excatly, I need to know the name of the executable file that is executed. originally, I try to windows service +...
2
2791
by: TwistedPair | last post by:
All, This is sort of a continuation of a previous post of mine. The code below basically reads a registry key to get a path to a folder and it watches for files created in that folder (only created). It also reads another registry key for another path which is a destination path. When a file shows up, it copies it off. It actually works...
6
1686
by: Andy B | last post by:
What would i use to look for changes in a file every minute?
0
8156
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. ...
0
8310
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...
1
7910
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...
0
8180
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...
0
6563
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
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...
0
3809
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...
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.