c USES filesystemwatcher to monitor file system changes
- 2020-06-07 05:12:29
- OfStack
#region Monitor folder changes
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "f:\\";
watcher.NotifyFilter =// The aspect being monitored
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName;
// To subscribe to 1 When it is triggered ( .net(windows) The underlying trigger, we don't care), executes our method
watcher.Changed += (object source, FileSystemEventArgs e) =>
{
Console.WriteLine(" file {0} Has been modified , Modify the type {1}", e.FullPath, e.ChangeType.ToString());
};
watcher.Created += (object source, FileSystemEventArgs e) =>
{
Console.WriteLine(" file {0} By establishing ", e.FullPath);
};
watcher.Deleted += (object source, FileSystemEventArgs e) =>
{
Console.WriteLine(" file {0} Has been deleted ", e.FullPath);
};
watcher.Renamed += (object source, RenamedEventArgs e) =>
{
Console.WriteLine(" file {0} The name has been removed from {1} Turned out to be {2}", e.OldFullPath, e.OldName, e.Name);
};
// for true According to open FileSystemWatcher Component, otherwise our monitoring will not activate
watcher.EnableRaisingEvents = true;
#endregion
In addition, I want to show you the technique of using an xor xor operation, that is, it can alternate the values of two variables without introducing a third variable. Your variable can be either a value or a character. If it is a character, we need to use its hashcode value for xor operation.
#region xor Exchange of two variables
int a = 2;
int b = 3;
Console.WriteLine("a={0}", a);
Console.WriteLine("b={0}", b);
a = a ^ b ^ (b = a);
Console.WriteLine("a={0}", a);
Console.WriteLine("b={0}", b);
#endregion