?
Solved

How to identify a directory has been replaced with same name using FileSystemWatcher

Posted on 2012-09-11
6
Medium Priority
?
325 Views
Last Modified: 2012-11-02
I want to identify whether a directory has been replaced by directory with same name  from other location....

Is  that possible using  FileSystemWatcher  to identify directory has been replaced or not?
0
Comment
Question by:devmasters
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38386771
I set NotifyFilter to "FileName" and trapped the Created() event:
    public partial class Form1 : Form
    {

        string FolderToWatch = @"C:\Users\Mike\Documents\temp";
        FileSystemWatcher FSW = new FileSystemWatcher();

        public Form1()
        {
            InitializeComponent();
            
            FSW.Path = FolderToWatch;
            FSW.NotifyFilter = NotifyFilters.FileName;
            FSW.EnableRaisingEvents = true;
            FSW.Created += new FileSystemEventHandler(FSW_Created);
        }

        void FSW_Created(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(FolderToWatch + " was created and/or replaced.");
        }

    }

Open in new window

0
 

Author Comment

by:devmasters
ID: 38390077
I guess , this will work only if you have files ..what if i don't have any files inside folder and trying to replace it. i want to handle folder based instead of file based
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38391435
Interesting...I can't get it to work with an empty folder either.  Windows asks for a confirmation about the replace, but the FileSystemWatcher doesn't see it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:devmasters
ID: 38458667
yeah...
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 38458679
Sorry man.  I couldn't find a solution for this problem.

What exactly are you doing that you need to know when an empty folder is replaced?
0
 

Author Closing Comment

by:devmasters
ID: 38559980
You are right :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question