Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- using System.Security.Permissions;
- using System.Configuration;
- namespace KlasaFileSystemWatcher
- {
- class Program
- {
- static string Sciezka = ConfigurationManager.AppSettings["Sciezka"];
- static string Zrodlo = ConfigurationManager.AppSettings["Zrodlo"];
- static string Dziennik = ConfigurationManager.AppSettings["Dziennik"];
- static void Main(string[] args)
- {
- Run();
- log
- }
- [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
- public static void Run()
- {
- FileSystemWatcher watcher = new FileSystemWatcher();
- watcher.Path = Sciezka;
- Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
- | NotifyFilters.FileName | NotifyFilters.DirectoryName;
- watcher.Filter = "*.txt";
- watcher.Changed += new FileSystemEventHandler(OnChanged);
- watcher.Created += new FileSystemEventHandler(OnChanged);
- watcher.Deleted += new FileSystemEventHandler(OnChanged);
- watcher.Renamed += new RenamedEventHandler(OnRenamed);
- watcher.EnableRaisingEvents = true;
- Console.WriteLine("Press \'q\' to quit the sample.");
- while (Console.Read() != 'q') ;
- }
- private static void OnChanged(object source, FileSystemEventArgs e)
- {
- Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
- }
- private static void OnRenamed(object source, RenamedEventArgs e)
- {
- Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment