Skip to content

Commit

Permalink
GetFilesCommand support extension
Browse files Browse the repository at this point in the history
  • Loading branch information
rcktrncn committed Jul 20, 2021
1 parent cf76dce commit 198f443
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion taskt/Core/Automation/Commands/GetFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public class GetFilesCommand : ScriptCommand
[Attributes.PropertyAttributes.Remarks("")]
public string v_SourceFolderPath { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Optional - Please indicate the extension (Default is empty and searched all files) (ex. txt, {{{vExtension}}})")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the extension.")]
[Attributes.PropertyAttributes.SampleUsage("**txt** or **{{{vExtension}}}**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_SearchExtension { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
Expand All @@ -46,9 +54,19 @@ public override void RunCommand(object sender)
//apply variable logic
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);

var ext = "." + v_SearchExtension.ConvertToUserVariable(sender).ToLower();

//delete folder
//System.IO.Directory.Delete(sourceFolder, true);
var filesList = System.IO.Directory.GetFiles(sourceFolder).ToList();
List<string> filesList;
if (String.IsNullOrEmpty(ext))
{
filesList = System.IO.Directory.GetFiles(sourceFolder).ToList();
}
else
{
filesList = System.IO.Directory.GetFiles(sourceFolder, "*.*").Where(t => System.IO.Path.GetExtension(t).ToLower() == ext).ToList();
}

Script.ScriptVariable newFilesList = new Script.ScriptVariable
{
Expand All @@ -70,6 +88,8 @@ public override List<Control> Render(frmCommandEditor editor)

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor));

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SearchExtension", this, editor));

RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this));
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor);
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor));
Expand Down

0 comments on commit 198f443

Please sign in to comment.