Watching for filesystem updates synchronous : FileSystemWatcher « File Directory Stream « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Mail;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;

public class MainClass
{
    public static void Main()
    {
        FileSystemWatcher watcher = new FileSystemWatcher(@"c:\", "*.*");
        // only rename event
        WaitForChangedResult result =watcher.WaitForChanged(WatcherChangeTypes.Changed | WatcherChangeTypes.Renamed);

        switch (result.ChangeType)
        {
            case WatcherChangeTypes.Changed:
                Console.WriteLine("{0}: File '{1}' was changed",DateTime.Now, result.Name);
                break;
            case WatcherChangeTypes.Renamed:
                Console.WriteLine("{0}: File '{1}' was renamed to '{2}'",DateTime.Now, result.OldName, result.Name);
                break;
        }
    }
}








15.36.FileSystemWatcher
15.36.1.Use FileSystemWatcher to detect file changes
15.36.2.Watching for filesystem updates synchronous
15.36.3.FileSystemWatcher Demo
15.36.4.File Watch
15.36.5.My Directory Watcher