mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-31 07:29:29 -06:00
68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using FileFlows.Plugin;
|
|
using FileFlows.Plugin.Attributes;
|
|
|
|
namespace FileFlows.BasicNodes.File;
|
|
|
|
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";
|
|
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/touch";
|
|
|
|
|
|
[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))
|
|
{
|
|
args.Logger?.ILog("Touching directory: " + 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
|
|
{
|
|
args.Logger?.ILog("Touching file: " + filename);
|
|
try
|
|
{
|
|
if (System.IO.File.Exists(filename))
|
|
System.IO.File.SetLastWriteTimeUtc(filename, DateTime.UtcNow);
|
|
else
|
|
System.IO.File.Create(filename);
|
|
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; }
|
|
}
|
|
}
|