namespace Automate.Commands; using System; using System.IO; class Files { public static void MakeFile(Automate au) { var loc = au.Stack.Pop!(); if(loc.HasValue && loc.VariantType == typeof(String)) { if(!File.Exists(loc.Get())) { var res = File.WriteAllText(loc.Get(),""); if(res case .Err) au.ThrowError(scope $"Could not create file at {loc.Get()}"); } else au.ThrowError("The file that is supposed to be created already exists"); } else au.ThrowError("Input parameter for makefile is not a string"); } public static void DeleteFile(Automate au) { var loc = au.Stack.Pop!(); if(loc.HasValue && loc.VariantType == typeof(String)) { if(File.Exists(loc.Get())) { var res = File.Delete(loc.Get()); if(res case .Err) au.ThrowError( scope $"Could not delete file with the name: {loc.Get()}"); } else au.ThrowError("Cannot delete a file that doesnt exist"); } else au.ThrowError("Input parameter for deletefile is not a string"); } public static void CopyFile(Automate au) { var dest = au.Stack.Pop!(); if(dest.HasValue && dest.VariantType == typeof(String)) { var target = au.Stack.Pop!(); if(target.HasValue && target.VariantType == typeof(String) && File.Exists(target.Get())) { File.Copy(target.Get(),dest.Get()) .IgnoreError(); } else au.ThrowError("Invalid target file"); } else au.ThrowError("Destination is not a string or unavailable"); } }