473,395 Members | 1,692 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,395 software developers and data experts.

FileSystemWatcher Folder Rename

D2
Hi,

We are using FileSystemWatcher class in a windows service to monitor a
directory "d:\abc". This path is configured in a config file. When the
service is running and FSW is watching this directory, user is able to
open up Windows Explorer and rename d:\abc to d:\xyz.

The problem here is, FSW doesnt fire any event for this hence my
program doesnt know that the monitored folder has been renamed. Next
time the service is started, it reads the path from config file and
exception is thrown as the folder doesnt exist (since d:\abc has been
renamed to d:\xyz). Is there any way by which I can come to know that
the monitored folder has been renamed??

thanks,
dapi
Sep 15 '08 #1
1 3164
Hi dapi,

Actually, the answer is very simple (I just tested it). You need to setup a
SECOND fsw. It will point to the parent of the subdirectory you are
monitoring and you can setup a filter that will be just the name of the
folder to prevent monitoring of other file/folder changes.

FileSystemWatcher fsw;
FileSystemWatcher fswParent;

fsw = new FileSystemWatcher(@"D:\abc");
fsw.Renamed += new RenamedEventHandler(fsw_Renamed);
fswParent = new FileSystemWatcher(@"D:\", "abc");
fswParent.Renamed += new RenamedEventHandler(fswParent_Renamed);
fswParent.EnableRaisingEvents = true;
fsw.EnableRaisingEvents = true;

Good luck,
Jim

"D2" wrote:
Hi,

We are using FileSystemWatcher class in a windows service to monitor a
directory "d:\abc". This path is configured in a config file. When the
service is running and FSW is watching this directory, user is able to
open up Windows Explorer and rename d:\abc to d:\xyz.

The problem here is, FSW doesnt fire any event for this hence my
program doesnt know that the monitored folder has been renamed. Next
time the service is started, it reads the path from config file and
exception is thrown as the folder doesnt exist (since d:\abc has been
renamed to d:\xyz). Is there any way by which I can come to know that
the monitored folder has been renamed??

thanks,
dapi
Sep 16 '08 #2

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

Similar topics

1
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...
1
by: Andreas | last post by:
Hi, we have some problems with the following situation: A remote application A writes files to a directory monitored by a FileSystemWatcher-instance in application B. A creates the file with...
20
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...
2
by: Brad | last post by:
Hello All I am working on an application that watches a folder for incomming files. The files happen to be tif files from a fax card. When the file comes in I want to move it to a different file....
1
by: Jason | last post by:
Given a scenario where I'm monitoring a folder, once the file has been created, I'd like to have it relocated to another folder via the File.Copy() method. My problem occurs when I paste a...
2
by: Steve | last post by:
I have a FileSystemWatcher watching a directory where I will add and update files. When it detects a change, I search through all the files and update my list of files in the UI. This works fine....
4
by: Stefan L | last post by:
Hi NG, I have a file driven application (a report server) which has to do some work when new files arrive or are deleted. When processing the notifications about newly created files from a...
2
by: Romain TAILLANDIER | last post by:
Hi group, I have created a very simple application to test the FileSystemWatcher. It is great ! I get all the event possible. but i need to make an operation AFTER a file is written, the...
3
by: =?Utf-8?B?RGFuaWVs?= | last post by:
I'm working with the FileSystemWatcher which has a Created event. But this event is raised as soon as the new file begins to be written on disk. What I want is a notification after a file being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.