added Touch node

This commit is contained in:
John Andrews
2022-04-22 16:29:36 +12:00
parent 419fc66af2
commit bac17d9a9b
14 changed files with 107 additions and 0 deletions

Binary file not shown.

View File

@@ -243,6 +243,16 @@
"CsvFile-Help": "Will append to this file the original name and the renamed file. Useful when using ''Log Only'' to test the renamer before changing files."
}
},
"Touch": {
"Description": "Touches a file or directory and sets the last write time to now.",
"Outputs": {
"1": "Successfully touched item"
},
"Fields": {
"FileName": "File Name",
"FileName-Help": "Full filename of file or folder to touch.\nIf left blank the working file will be used."
}
},
"WebRequest": {
"Description": "Allows you to send a web request",
"Outputs": {

59
BasicNodes/File/Touch.cs Normal file
View File

@@ -0,0 +1,59 @@
namespace FileFlows.BasicNodes.File;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
public class Touch : Node
{
public override int Inputs => 1;
public override int Outputs => 1;
public override FlowElementType Type => FlowElementType.Process;
public override string Icon => "fas fa-hand-point-right";
[TextVariable(1)]
public string FileName { get; set; }
public override int Execute(NodeParameters args)
{
string filename = args.ReplaceVariables(this.FileName ?? string.Empty, stripMissing: true);
if (string.IsNullOrEmpty(filename))
filename = args.WorkingFile;
if (IsDirectory(filename))
{
try
{
var dir = new DirectoryInfo(filename);
Directory.SetLastWriteTimeUtc(filename, DateTime.UtcNow);
return 1;
}
catch (Exception ex)
{
args.Logger?.ELog("Failed to touch directory: " + ex.Message);
return -1;
}
}
else
{
try
{
System.IO.File.SetLastWriteTimeUtc(filename, DateTime.UtcNow);
return 1;
}
catch (Exception ex)
{
args.Logger?.ELog($"Failed to touch file: '{filename}' => {ex.Message}");
return -1;
}
}
}
private bool IsDirectory(string filename)
{
try
{
return new DirectoryInfo(filename).Exists;
}
catch (Exception) { return false; }
}
}

View File

@@ -0,0 +1,38 @@
#if(DEBUG)
namespace BasicNodes.Tests;
using FileFlows.BasicNodes.File;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class TouchTests
{
FileFlows.Plugin.NodeParameters Args;
[TestInitialize]
public void TestStarting()
{
Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", new TestLogger(), false, string.Empty);
}
[TestMethod]
public void Touch_File()
{
Touch node = new ();
node.FileName = @"D:\videos\testfiles\basic.mkv";
var result = node.Execute(Args);
Assert.AreEqual(1, result);
}
[TestMethod]
public void Touch_Folder()
{
Touch node = new();
node.FileName = @"D:\videos\testfiles";
var result = node.Execute(Args);
Assert.AreEqual(1, result);
}
}
#endif