Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - FileSystemWatcher Folder Rename

Reply
 
Old 09-15-2008   #1 (permalink)
D2


 
 

FileSystemWatcher Folder Rename

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

My System SpecsSystem Spec
Old 09-15-2008   #2 (permalink)
JimF


 
 

RE: FileSystemWatcher Folder Rename

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:
Quote:

> 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
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Solved Could not rename the folder name General Discussion
Folder will not rename. General Discussion
FileSystemWatcher not monitoring UNC folder .NET General
Can't rename a folder Vista General
FileSystemWatcher not reporting files in folder moved to Recycle Bin? .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46