Absolutely dumb code, works in both linux and windows net core 3.1 and higher.
Change OnChanged where the full name of the file arrives, add your logic.
Change OnChanged where the full name of the file arrives, add your logic.
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);
}
}
}