Solved

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

Posted on 2012-03-29
3
534 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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