Liquid Studio 2021
Data Mapping / Data Mapper Functions / By Category / File / List Files
In This Topic
    List Files
    In This Topic

    Function Name
    List Files
    Category
    File
    Icon
    Description
    Gets a all the files in a directory that match a given pattern
    Inputs
    Path

    The directory that function will enumerate all the files within (optional)
    If it's not connected the value is read from the internal property "File Path".

    Outputs
    Filename A list of all the files in the "File Path" that match the "pattern".
    This is the full path to the file
    Properties
    File Path If the input connection point "FilePath" is not connected then this directory is the one enumerated.
    Pattern A standard DOS style pattern to filter files i.e. *.xml
    Recursive true/false if this is true then all the child directories are also searched.

    Usage

    The Data Mapper ListFiles function converts reads all the files matching the provided pattern. This is useful for reading multiple input files :

    In the following example the filenames taken from the ListFiles component are fed into the XML Readers Filename input. So every filename that ListFiles returns is opened as an XML document:

    If we have the following input files in the target folder

    Input001.xml
    Copy Code
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Created with Liquid XML Studio (https://www.liquid-technologies.com) -->
    <bookstore xmlns="https://www.liquid-technologies.com/sample/bookstore">
     <book price="4.99" publicationdate="2008-10-20" ISBN="978-0747596837">
      <title>The Graveyard Book</title>
      <author>
       <first-name>Neil</first-name>
       <last-name>Gaiman</last-name>
      </author>
      <genre>Horror</genre>
     </book>
     <book price="21.99" publicationdate="2002-05-14" ISBN="0-596-00252-1">
      <title>XML Schemas</title>
      <author>
       <first-name>Eric</first-name>
       <last-name>van der Vlist</last-name>
      </author>
      <genre>Reference</genre>
     </book>
    </bookstore>
    
    Input002.xml
    Copy Code
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Created with Liquid XML Studio (https://www.liquid-technologies.com) -->
    <bookstore xmlns="https://www.liquid-technologies.com/sample/bookstore">
     <book price="5.99" publicationdate="1999-05-02" ISBN="0-945-16546-1">
      <title>The Portable Door</title>
      <author>
       <first-name>Tom</first-name>
       <last-name>Holt</last-name>
      </author>
      <genre>Fiction</genre>
     </book>
    </bookstore>
    

    The if the ListFiles function is configured with a pattern say "input*.xml" then the 2 files will be read into the XML Reader and passed onto the writer resulting in;

    Output XML
    Copy Code
    <bookstore xmlns="https://www.liquid-technologies.com/sample/bookstore">
      <book>
        <title>The Graveyard Book</title>
      </book>
      <book>
        <title>XML Schemas</title>
      </book>
      <book>
        <title>The Portable Door</title>
      </book>
    </bookstore>
    
    Properties

    The ListFiles properties values can be edited using the Properties Window.

    Example

    A range of functions are provided for working with Uri's and Path's. The following example demonstrates how these can be used.

     

    In the following example we have a directory c:\UriExamples\ that contains the files Bookstore.xsd, Input001.xml, Input002.xml & ResolvedUri.Output.xml.

    In our transform we have configured "ListFiles" to operate on the directory "c:\UriExamples\" and use the pattern "Input*.xml"

    As you can see the ListFiles component gets the full paths of all the files that match the pattern. These filenames are then fed into the various Uri functions and output into an XML writer.

    The result of the transform is as follows

    Transform Output
    Copy Code
    <FileProperties>
      <File>
        <FullFilename>C:\UriExamples\Input001.xml</FullFilename>
        <Filename>Input001.xml</Filename>
        <Extension>.xml</Extension>
        <Path>C:\UriExamples</Path>
        <AltFullFilename>C:\UriExamples\Backup\Input001.xml</AltFullFilename>
        <BackupFilename>C:\UriExamples\Input001.xml.bak</BackupFilename>
      </File>
      <File>
        <FullFilename>C:\UriExamples\Input002.xml</FullFilename>
        <Filename>Input002.xml</Filename>
        <Extension>.xml</Extension>
        <Path>C:\UriExamples</Path>
        <AltFullFilename>C:\UriExamples\Backup\Input002.xml</AltFullFilename>
        <BackupFilename>C:\UriExamples\Input002.xml.bak</BackupFilename>
      </File>
    </FileProperties>
    

    Let's examine the output in more detail

    This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

    See Also