listfiles
The [listfiles] context will display a list of all the files & folders within a folder.
Parameters
Parameter | Description |
---|---|
path | (required) The path to the folder which is to be listed. This path is relative to the template. |
ShowInvisibles | (optional) Apple platform only: if set to T, then display invisible filenames, if set to F, do not display invisible filenames |
Name | (optional) filters files by name |
Exact | (optional, used with Name) if set to T, then display filenames that match 'Name' criteria exactly; if set to F, a partial match can be made |
Tags available inside the [listfiles] context
Tag | Description |
---|---|
[isfolder] | "T" if this item is a folder. "F" otherwise. |
[isfile] | "T" if this item is a file. "F" otherwise. |
[filename] | Name of the file. |
[fullpath] | Full path to the file, starting from its containing FolderPath. |
[moddate] | Last date the file was modified. |
[modtime] | Last time the file was modified. |
[createdate] | Date the file was created. |
[createtime] | Time the file was created. |
[size] | The file's size, in bytes. |
[index] | The file's position in the list |
[startpath] | The folder path leading to the file. |
[break] | From version 8.1, if the [listfiles] context sees the [break] tag while executing a loop, it will stop looping, once it finishes the current loop. Thus the [break] tag should only appear in a [showif] statement that is evaluated at the end (bottom) of the loop. |
Example WebDNA code:
Use the "Name" and "Exact" parameters with the [listfiles] context to "filter" the results inside a [listfiles] context.
If the current folder contains the files:
file1.txt
file2.txt
file2.txt
Example WebDNA code:
List all the .png & .jpg files in a folder named "images":
file1.txt
file2.png
file3.txt
file4.gif
file5.jpg
file2.png
file5.jpg
Use the "Name" and "Exact" parameters with the [listfiles] context to "filter" the results inside a [listfiles] context.
If the current folder contains the files:
file1.txt
file2.txt
file2.txt
[listfiles path=/&name=file1&exact=f]
[filename]
[/listfiles]
Results: file1.txtExample WebDNA code:
List all the .png & .jpg files in a folder named "images":
file1.txt
file2.png
file3.txt
file4.gif
file5.jpg
[listfiles path=images/]
[showif [isfile]=T]
[if ("[filename]" ^ ".png")|("[filename]" ^ ".jpg")]
[then]
[filename]
[/then]
[else][/else]
[/if]
[/showif]
[/listfiles]
Results:file2.png
file5.jpg
There is no facility for sorting the file list within the [listfiles] context. This is determined by the server. One way to sort is to capture the results in a [table] context, then search and sort the table as desired.