forked from ebrasha/Abdal-FileWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
89 lines (70 loc) · 4.63 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace FileWatcherExample
{
class Program
{
private static List<FileSystemWatcher> watchers = new List<FileSystemWatcher>();
static void Main()
{
var banner = @"
░█████╗░██████╗░██████╗░░█████╗░██╗░░░░░
██╔══██╗██╔══██╗██╔══██╗██╔══██╗██║░░░░░
███████║██████╦╝██║░░██║███████║██║░░░░░
██╔══██║██╔══██╗██║░░██║██╔══██║██║░░░░░
██║░░██║██████╦╝██████╔╝██║░░██║███████╗
╚═╝░░╚═╝╚═════╝░╚═════╝░╚═╝░░╚═╝╚══════╝
███████╗██╗██╗░░░░░███████╗░██╗░░░░░░░██╗░█████╗░████████╗░█████╗░██╗░░██╗███████╗██████╗░
██╔════╝██║██║░░░░░██╔════╝░██║░░██╗░░██║██╔══██╗╚══██╔══╝██╔══██╗██║░░██║██╔════╝██╔══██╗
█████╗░░██║██║░░░░░█████╗░░░╚██╗████╗██╔╝███████║░░░██║░░░██║░░╚═╝███████║█████╗░░██████╔╝
██╔══╝░░██║██║░░░░░██╔══╝░░░░████╔═████║░██╔══██║░░░██║░░░██║░░██╗██╔══██║██╔══╝░░██╔══██╗
██║░░░░░██║███████╗███████╗░░╚██╔╝░╚██╔╝░██║░░██║░░░██║░░░╚█████╔╝██║░░██║███████╗██║░░██║
╚═╝░░░░░╚═╝╚══════╝╚══════╝░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝
----------------------------------------------------
Programmer: Ebrahim Shafiei (EbraSha)
Email: Prof.Shafiei@Gmail.com
----------------------------------------------------
";
Console.BackgroundColor = ConsoleColor.Blue;
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Version version = Assembly.GetExecutingAssembly().GetName().Version;
Console.Title = "Abdal FileWatcher " + version.Major + "." + version.Minor;
Console.WriteLine(banner);
// Get a list of all available drives
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo drive in allDrives)
{
// Check if the drive is ready
if (!drive.IsReady)
{
Console.WriteLine($"Drive {drive.Name} is not ready. Skipping...");
continue;
}
// Create a FileSystemWatcher for each drive
var watcher = new FileSystemWatcher
{
Path = drive.Name,
NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName,
IncludeSubdirectories = true // Monitor subdirectories as well
};
watcher.Created += OnChanged;
watcher.EnableRaisingEvents = true;
watchers.Add(watcher);
}
Console.WriteLine("Monitoring all drives. Press 'q' to quit.");
while (Console.Read() != 'q') ;
// Dispose resources once monitoring is done
foreach (var watcher in watchers)
{
watcher.Dispose();
}
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine($"Change detected: {e.FullPath}"+"\n");
}
}
}