?
Solved

How to capture FileSystemWatcher events  for the watch directory itself using C#

Posted on 2012-03-29
3
Medium Priority
?
549 Views
Last Modified: 2012-03-29
How can I capture FileSystem events for the watch directory( not the subdirectory) if I delete/rename  the watch folder named "C:\FileWatcher".

 ie, my watch directory is FileWatcher, if user delete FileWatcher, I need to get the delete events for the directory FileWatcher, similarly rename also. Is there any way to do this in C#?

Please help.
0
Comment
Question by:HPFE455
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 total points
ID: 37782119
here is an extension to it, that even tells you if the folder being watched is deleted:-

http://www.codeproject.com/Articles/15656/Advanced-FileSystemWatcher

Here is another interesting extension (not related to your question, but still interesting, i am sure you would like it):_
http://www.codeproject.com/Articles/102493/Enhanced-FileSystemWatcher
0
 

Author Comment

by:HPFE455
ID: 37782527
Thanks  BuggyCoder, I think your solution is apt to my requirement, I am trying to implement the timer in my code

System.Timers.Timer myTimer = new System.Timers.Timer();
myTimer.Elapsed += new ElapsedEventHandler(OnElapsedTimer);
myTimer.Interval = 5000;
myTimer.Enabled = true;

private static void OnDeleted(object source, RenamedEventArgs e)   
{
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);

}

 private static void OnElapsedTimer(object source, ElapsedEventArgs e)
    {
         path = "C:\MyMusic"
         if (!Directory.Exists(path))         
       {
        // Here I need invoke OnDeleted File Watcher method if the directory does not exist

       }
}

Open in new window


How can I invoke OnDeleted  method, if watch directory does not exist?
0
 

Author Closing Comment

by:HPFE455
ID: 37783955
Thanks for providing me the solution
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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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