using FileFlows.Plugin; using FileFlows.Plugin.Attributes; namespace FileFlows.BasicNodes.File; /// /// Checks if a file exists /// public class FileExists: Node { /// public override int Inputs => 1; /// public override int Outputs => 2; /// public override FlowElementType Type => FlowElementType.Logic; /// public override string Icon => "fas fa-question-circle"; /// public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/file-exists"; /// public override bool NoEditorOnAdd => true; /// /// Gets or sets the name of the file to check /// Leave blank to test the working file /// [TextVariable(1)] public string FileName { get; set; } /// public override int Execute(NodeParameters args) { string file = args.ReplaceVariables(FileName ?? string.Empty, true)?.EmptyAsNull() ?? args.WorkingFile; if(string.IsNullOrWhiteSpace(file)) { args.FailureReason = "FileName not set"; args.Logger?.ELog(args.FailureReason); return -1; } try { var result = args.FileService.FileExists(file); if (result.Is(true)) { args.Logger?.ILog("File does exist: " + file); return 1; } args.Logger?.ILog("File does NOT exist: " + file); return 2; } catch (Exception ex) { args.FailureReason = $"Failed testing if file '{file}' exists: " + ex.Message; args.Logger?.ELog(args.FailureReason); return -1; } } }