Guest User

Untitled

a guest
Dec 4th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Diagnostics;
  7. using System.Security.Permissions;
  8. using System.Configuration;
  9.  
  10.  
  11. namespace KlasaFileSystemWatcher
  12. {
  13. class Program
  14. {
  15. static string Sciezka = ConfigurationManager.AppSettings["Sciezka"];
  16. static string Zrodlo = ConfigurationManager.AppSettings["Zrodlo"];
  17. static string Dziennik = ConfigurationManager.AppSettings["Dziennik"];
  18.  
  19.  
  20. static void Main(string[] args)
  21. {
  22. Run();
  23. log
  24.  
  25.  
  26. }
  27.  
  28. [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
  29. public static void Run()
  30. {
  31. FileSystemWatcher watcher = new FileSystemWatcher();
  32. watcher.Path = Sciezka;
  33. Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  34.  
  35. watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
  36. | NotifyFilters.FileName | NotifyFilters.DirectoryName;
  37. watcher.Filter = "*.txt";
  38.  
  39. watcher.Changed += new FileSystemEventHandler(OnChanged);
  40. watcher.Created += new FileSystemEventHandler(OnChanged);
  41. watcher.Deleted += new FileSystemEventHandler(OnChanged);
  42. watcher.Renamed += new RenamedEventHandler(OnRenamed);
  43.  
  44. watcher.EnableRaisingEvents = true;
  45.  
  46. Console.WriteLine("Press \'q\' to quit the sample.");
  47. while (Console.Read() != 'q') ;
  48. }
  49.  
  50. private static void OnChanged(object source, FileSystemEventArgs e)
  51. {
  52. Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
  53. }
  54.  
  55. private static void OnRenamed(object source, RenamedEventArgs e)
  56. {
  57. Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment