- I need the following for adding and removing files and folders.
- I need to watch for changes in files and folders.
- All actions must be recursively.
How to do it all on c#?
How to do it all on c#?
Use
FileSystemWatcherHere is a simple code example watching for created file:
public void Watcher()
{
//Create a new FileSystemWatcher.
FileSystemWatcher watcher = new FileSystemWatcher();
//Set the filter to only catch TXT files.
watcher.Filter = "*.txt";
//Subscribe to the Created event.
//Created Occurs when a file or directory in the specified Path is created.
//You can change this based on what you are trying to do.
watcher.Created += new FileSystemEventHandler(YOUR_EVENT_HANDLER);
//Set the path to you want to monitor
watcher.Path = @"C:\PATH\";
//Enable the FileSystemWatcher events.
watcher.EnableRaisingEvents = true;
}