diff --git a/BasicNodes/File/MoveDirectory.cs b/BasicNodes/File/MoveDirectory.cs new file mode 100644 index 00000000..cf6a0597 --- /dev/null +++ b/BasicNodes/File/MoveDirectory.cs @@ -0,0 +1,87 @@ +using System.ComponentModel.DataAnnotations; +using FileFlows.Plugin; +using FileFlows.Plugin.Attributes; + +namespace FileFlows.BasicNodes.File; + +/// +/// Flow element that moves a directory +/// +public class MoveDirectory : Node +{ + /// + public override int Inputs => 1; + /// + public override int Outputs => 1; + /// + public override FlowElementType Type => FlowElementType.Process; + /// + public override string Icon => "fas fa-people-carry"; + /// + public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/move-directory"; + + /// + /// Gets or sets the source path to move + /// + [TextVariable(1)] + public string SourcePath { get; set; } + + /// + /// Gets or sets the destination path + /// + [Required] + [Folder(2)] + public string DestinationPath { get; set; } + + /// + public override int Execute(NodeParameters args) + { + string source = args.ReplaceVariables(SourcePath ?? string.Empty)?.EmptyAsNull() ?? args.WorkingFile; + + bool updateWorkingFolder = args.WorkingFile == source; + + var existsResult = args.FileService.DirectoryExists(source); + if (existsResult.Failed(out var error)) + { + args.FailureReason = error; + args.Logger?.ELog(error); + return -1; + } + + if (existsResult.Value == false) + { + args.FailureReason = "Directory does not exists: " + source; + args.Logger?.ELog(args.FailureReason); + return -1; + } + + var dest = args.ReplaceVariables(DestinationPath ?? string.Empty); + if (string.IsNullOrWhiteSpace(dest)) + { + args.FailureReason = "No destination path set"; + args.Logger?.ELog(args.FailureReason); + return -1; + } + + args.Logger?.ILog("Moving Directory: " + source); + args.Logger?.ILog("Destination Directory: " + dest); + + var moveResult = args.FileService.DirectoryMove(source, dest); + if (moveResult.Failed(out error)) + { + args.FailureReason = error; + args.Logger?.ELog(error); + return -1; + } + + if (updateWorkingFolder) + { + args.Logger?.ILog("Updating working folder to: " + dest); + args.SetWorkingFile(dest, dontDelete: true); + } + + args.Logger?.ILog("Directory moved"); + return 1; + + } +} \ No newline at end of file diff --git a/BasicNodes/i18n/en.json b/BasicNodes/i18n/en.json index d7c11162..9bde5d48 100644 --- a/BasicNodes/i18n/en.json +++ b/BasicNodes/i18n/en.json @@ -407,6 +407,16 @@ "MatchConditions-Help": "The matches to test which output should be called." } }, + "MoveDirectory": { + "Description": "Moves a directory", + "Outputs": { + "1": "Directory moved", + }, + "SourcePath": "Directory", + "SourcePath-Help": "The directory to move, if left blank the Working File will be used, if this is not a directory., then the flow element will fail", + "DestinationPath": "Destination", + "DestinationPath-Help": "The destination directory to move the Directory into." + }, "MoveFile": { "Description": "Moves a file to the destination folder", "Outputs": {