• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

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

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
devmasters
Asked:
devmasters
  • 3
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
devmastersAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
devmastersAuthor Commented:
yeah...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
devmastersAuthor Commented:
You are right :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now