FileSystemWatcher Folder Rename

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D2

    FileSystemWatcher Folder Rename

    Hi,

    We are using FileSystemWatch er 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
  • =?Utf-8?B?SmltRg==?=

    #2
    RE: FileSystemWatch er 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.

    FileSystemWatch er fsw;
    FileSystemWatch er fswParent;

    fsw = new FileSystemWatch er(@"D:\abc");
    fsw.Renamed += new RenamedEventHan dler(fsw_Rename d);
    fswParent = new FileSystemWatch er(@"D:\", "abc");
    fswParent.Renam ed += new RenamedEventHan dler(fswParent_ Renamed);
    fswParent.Enabl eRaisingEvents = true;
    fsw.EnableRaisi ngEvents = true;

    Good luck,
    Jim

    "D2" wrote:
    Hi,
    >
    We are using FileSystemWatch er 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
    >

    Comment

    Working...