using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace FileSystemWatcherLab
{
internal class Test1
{
public void Execute()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "S:\\Filewatcher";
watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size;
watcher.IncludeSubdirectories = true; watcher.Changed += this.OnChanged;
watcher.Created += this.OnCreated;
watcher.Deleted += this.OnDeleted;
watcher.Renamed += this.OnRenamed; watcher.EnableRaisingEvents = true;
} /// <summary>
/// On path changed event.
/// </summary>
/// <param name="source">Changed source.</param>
/// <param name="e">Path change event args.</param>
private void OnCreated(object source, FileSystemEventArgs e)
{
Console.WriteLine("Created");
Console.WriteLine(e.FullPath);
Console.WriteLine();
} /// <summary>
/// On path changed event.
/// </summary>
/// <param name="source">Changed source.</param>
/// <param name="e">Path change event args.</param>
private void OnDeleted(object source, FileSystemEventArgs e)
{
Console.WriteLine("Deleted");
Console.WriteLine(e.FullPath);
Console.WriteLine();
} /// <summary>
/// On path changed event.
/// </summary>
/// <param name="source">Changed source.</param>
/// <param name="e">Path change event args.</param>
private void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("Changed");
Console.WriteLine(e.FullPath);
Console.WriteLine();
} /// <summary>
/// On path rename event.
/// </summary>
/// <param name="source">Rename source.</param>
/// <param name="e">Path rename args.</param>
private void OnRenamed(object source, RenamedEventArgs e)
{
Console.WriteLine("Renamed");
Console.WriteLine(e.FullPath);
Console.WriteLine();
}
}
}
04-13 20:15