Created
February 15, 2022 19:43
-
-
Save ChrisPritchard/e27edaa8f8fcf3ad13dd26d1d5744a24 to your computer and use it in GitHub Desktop.
A simple filewatcher used to preserve any files created and then renamed in a directory. Used for some save file shenanigans with Pillars of Eternity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watcher = new FileSystemWatcher(".") { EnableRaisingEvents = true }; | |
watcher.Renamed += (_, e) => | |
{ | |
if(Path.GetExtension(e.Name) != ".savegame") | |
{ | |
Console.WriteLine($"Ignoring {Path.GetExtension(e.Name)} file"); | |
return; | |
} | |
try | |
{ | |
System.IO.File.Copy(e.FullPath, @"C:\Users\Christopher\Desktop\bak\" + e.Name); | |
Console.WriteLine("Copied " + e.Name); | |
} | |
catch (System.Exception ex) | |
{ | |
Console.WriteLine("Failed to copy " + e.Name + ": " + ex.Message); | |
} | |
}; | |
Console.WriteLine("Watching. Press any key to exit"); | |
Console.ReadLine(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment