Абсолютно тупой код, работает как в линуксе так и в windows net core 3.1 и выше.
Измените OnChanged туда прилетает полное имя файла, добавьте свою логику.
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace watcher
{
internal class Program
{
private static string _exePath;
private static int Main(string[] args)
{
if (args.Length < 2) return ShowHelp();
var watchFolder = args[0];
_exePath = args[1];
var watcher = new FileSystemWatcher
{
Path = watchFolder,
Filter = "*.*",
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName,
EnableRaisingEvents = true
};
watcher.Created += OnChanged;
while (true)
{
Thread.Sleep(1000);
}
}
private static int ShowHelp()
{
Console.WriteLine("usage: watcher path_to_watch_folder path_to_executable");
return -1;
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.FullPath);
Process.Start(_exePath, e.FullPath);
}
}
}