Solved

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

Posted on 2012-03-29
3
527 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
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now