Cc monitors file addition or deletion events through FileSystemWatcher

From , 3 Years ago, written in C#, viewed 225 times.
URL https://pastebin.vip/view/b8b2926b
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4.  
  5. class MainClass {
  6.     static void Main(string[] args) {
  7.         using (FileSystemWatcher watch = new FileSystemWatcher()) {
  8.             watch.Path = Application.StartupPath;
  9.             watch.Filter = "*.*";
  10.             watch.IncludeSubdirectories = true;
  11.  
  12.             // Attach the event handler.
  13.             watch.Created += new FileSystemEventHandler(OnCreatedOrDeleted);
  14.             watch.Deleted += new FileSystemEventHandler(OnCreatedOrDeleted);
  15.             watch.EnableRaisingEvents = true;
  16.  
  17.             Console.WriteLine("Press Enter to create a  file.");
  18.             Console.ReadLine();
  19.  
  20.             if (File.Exists("test.bin")) {
  21.                 File.Delete("test.bin");
  22.             }
  23.  
  24.             // Create test.bin.
  25.             using (FileStream fs = new FileStream("test.bin", FileMode.Create)) {
  26.                 // Do something.
  27.             }
  28.  
  29.             Console.WriteLine("Press Enter to terminate the application.");
  30.             Console.ReadLine();
  31.         }
  32.     }
  33.  
  34.     private static void OnCreatedOrDeleted(object sender, FileSystemEventArgs e) {
  35.         Console.WriteLine("\tNOTIFICATION: " + e.FullPath + "' was " + e.ChangeType.ToString());
  36.         Console.WriteLine();
  37.     }
  38. }
  39. //csharp/7637

Reply to "Cc monitors file addition or deletion events through FileSystemWatcher"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website