pc:Directory

Previous Next

Returns a directory-and-file description of the contents of a directory node in the file system, allowing you to loop over a set of files. This description contains, for each directory and each file:

The local name of the directory or file.

The full path leading to the directory or file.

A timestamp indicating the time and date when the directory or file was last modified.

Returns an XML fragment.

Syntax

<pc:Directory
     filepath="file-path"
     select="xpath"
     filter="path-pattern"
     subdirlevel="integer"
     before="date"
     after="date"
/>

The required filepath points to the directory that you want a description of.

The optional select attribute is a filter that selects specific nodes from the returned XML document, as shown in Examples 2 and 3. The xpath-expression location path is evaluated relative to the root node of this XML document, regardless of whether it is a relative or absolute location path.

The optional filter attribute is a file name pattern applied to the result, as shown in Example 3. If the result lists files (at any level of the directory tree), then

filter="*.xml"

causes the result to list only files that have the "*.xml" extension.

The optional subdirlevel is a filter that restricts to a maximum level of subdirectories. Its value must be a positive integer or 0 (zero). If its value is 1, only the contents of the directory itself and its first-level subdirectories are returned. If its value is 0, no information on subdirectories is returned.

The optional before and after allow you to specify that you only want information on files before, or after, or between, the specified date value(s). See the "Before and after" section below. Date must be in a date format that can be interpreted in USoft Blend.

 

Example 1

<pc:Directory filepath="c:\temp" />

An example result is:

<Directory dirpath="c:\temp\" dirname="temp" lastwrite="2019/0109100614">
  <Directory dirpath="c:\temp\mydir2" dirname="mydir2" lastwrite="2019/0109100620">
    <File filepath="c:\temp\mydir2\myfile4.txt" filename="myfile4.txt" lastwrite="2019/0109100021" />
  </Directory>
    <File filepath="c:\temp\myfile1.xml" filename="myfile1.xml" lastwrite="2019/0109093257" />
    <File filepath="c:\temp\myfile2.xml" filename="myfile2.xml" lastwrite="2019/0109083456" />
    <File filepath="c:\temp\myfile3.txt" filename="myfile3.txt" lastwrite="2019/0108180520" />
</Directory>

 

Example 2

<pc:Directory filepath="c:\temp" select="Directory/File" />

An example result is:

<File filepath="c:\temp\myfile1.xml" filename="myfile1.xml" lastwrite="2019/0109093257" />
<File filepath="c:\temp\myfile2.xml" filename="myfile2.xml" lastwrite="2019/0109083456" />
<File filepath="c:\temp\myfile3.txt" filename="myfile3.txt" lastwrite="2019/0108180520" />

 

Example 3

<pc:Directory filepath="c:\temp" select="Directory/File" filter="*.xml" />

An example result is:

<File filepath="c:\temp\myfile1.xml" filename="myfile1.xml" lastwrite="2019/0109093257" />
<File filepath="c:\temp\myfile2.xml" filename="myfile2.xml" lastwrite="2019/0109083456" />

This is more efficient than the following, because the result is filtered upfront, as opposed to the whole set being retrieved before it is filtered:

<pc:Directory filepath="c:\temp" select="Directory/File[strings:EndsWith(@filename,'.xml')]" />

 

collapseBefore and after