469,959 Members | 1,905 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,959 developers. It's quick & easy.

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 2985
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Troy Murphy | last post: by
2 posts views Thread by Brad | last post: by
4 posts views Thread by Stefan L | last post: by
2 posts views Thread by Romain TAILLANDIER | last post: by
3 posts views Thread by =?Utf-8?B?RGFuaWVs?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.