{
  "Name": "FilesInDirectory",
  "_id": "a3e5722b-51a2-479d-b99f-3249e332b89c",
  "Namespace": "lib.basic.file",
  "Description": "Returns a dynamic list of Strings with relative filepaths to each file. Use [[NthString]] or [[ListLength]] to access it.",
  "Inputs": [
    {
      "Name": "DirectoryPath",
      "MetaInstanceID": "2a57fe51-2660-4404-8795-54e9345cf53b",
      "DefaultValue": {
        "Type": "Text",
        "Value": "test.txt"
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Match",
      "MetaInstanceID": "d3778463-2309-4857-a6a3-eff2cb289eab",
      "DefaultValue": {
        "Type": "Text",
        "Value": ".*"
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Dynamic",
      "MetaInstanceID": "38cc1bf7-fee3-47f4-8eb9-aa1842dc8936",
      "MetaID": "9701d534-b3ff-4889-a250-84aece4a7d76"
    },
    {
      "Name": "Count",
      "MetaInstanceID": "b97dcfda-645f-408a-a84e-6c1961249197",
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "d03608bb-780b-488e-b964-337b83446118",
      "MetaID": "c593c7f5-15b3-4196-a30d-01adf8ab7445",
      "Name": "FilesInDirectoryFunc",
      "Version": "9942b53a-d8d4-42bc-bd1e-5ebacfe67e9c",
      "Type": "Dynamic",
      "IsMultiInput": "True",
      "Script": [
        "//>>> _using",
        "using System;",
        "using System.Collections.Generic;",
        "using System.Linq;",
        "using System.Text;",
        "using SharpDX;",
        "using SharpDX.Direct3D11;",
        "using SharpDX.Windows;",
        "//<<< _using",
        "",
        "using System.IO;",
        "using System.Dynamic;",
        "using System.Text.RegularExpressions;",
        "",
        "namespace Framefield.Core.IDc593c7f5_15b3_4196_a30d_01adf8ab7445",
        "{",
        "    public class Class_FilesInDirectory : OperatorPart.Function",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            DirectoryPath = 0,",
        "            Match = 1",
        "        }",
        "        //<<< _inputids",
        "",
        "        //>>> _outputids",
        "        private enum OutputId",
        "        {",
        "            Dynamic = 0,",
        "            Count = 1",
        "        }",
        "        //<<< _outputids",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) {",
        "            //>>> _params",
        "            var DirectoryPath = inputs[(int)InputId.DirectoryPath].Eval(context).Text;",
        "            var Match = inputs[(int)InputId.Match].Eval(context).Text;",
        "            //<<< _params",
        "",
        "",
        "            if( DirectoryPath != _directoryPath || Match != _matchString) {",
        "                _list = new List<string>();",
        "                _directoryPath = DirectoryPath;",
        "                _matchString = Match;",
        "    ",
        "                try",
        "                {",
        "",
        "                    _list.AddRange(from filename in Directory.GetFiles(DirectoryPath) ",
        "                                  let basename = filename.Split('\\\\').Last() ",
        "                                  where Regex.Match(basename, Match, RegexOptions.IgnoreCase).Success ",
        "                                  select filename);",
        "                }",
        "                ",
        "",
        "                catch (DirectoryNotFoundException)",
        "                {",
        "                    Logger.Warn(\"Cound not read directory '{0}'\", DirectoryPath);",
        "                }",
        "                catch (ArgumentException)",
        "                {",
        "                    Logger.Warn(\"Invalid directory path '{0}'\", DirectoryPath);",
        "                }",
        "                catch",
        "                {",
        "                    Logger.Warn(\"could not acces directory path '{0}'\", DirectoryPath);",
        "                }",
        "            }",
        "            ",
        "            switch(outputIdx) {",
        "                case  (int)OutputId.Dynamic:",
        "                    context.Dynamic = _list;",
        "                    break;",
        "                case  (int)OutputId.Count:",
        "                    context.Value = _list.Count;    // FIXME: This is never called?",
        "                    break;",
        "            }",
        "            context.Value = _list.Count;",
        "            return context;",
        "            ",
        "         ",
        "        }",
        "        ",
        "        private string _directoryPath;",
        "        private string _matchString;",
        "        private List<string> _list = new List<string>();",
        "        ",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2a57fe51-2660-4404-8795-54e9345cf53b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "d03608bb-780b-488e-b964-337b83446118"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d3778463-2309-4857-a6a3-eff2cb289eab",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "d03608bb-780b-488e-b964-337b83446118"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d03608bb-780b-488e-b964-337b83446118",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "38cc1bf7-fee3-47f4-8eb9-aa1842dc8936"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d03608bb-780b-488e-b964-337b83446118",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b97dcfda-645f-408a-a84e-6c1961249197"
    }
  ]
}