Docly Developers
DocsUpdated 22 Oct 2026

GetFiles and Folders - examples

Examples for using the functions above. Also sorting documents or folders on custom properties.

listFiles(path, wildcard)

Fastest way to retrieve files:

#let files = docly.listFiles("/")#
#for (let file of files) {#
    <div>#file.Name#</div>
#}#

Returns following structure, see link:

getFiles(path, [options])

Parameter name

Type

Description

path

string

Absolute path to folder (from site root).

options (optional)

object

An object with any of the following properties:

• name (string) - Filename wildcard (e.g. ".pdf"), default is ""
• depth (number) - Subfolder levels to traverse, default is 0
• mode (enum) - Detail level: "Full", "Medium" (default), "Min"
• schema (string) - Schema name wildcard, default is "*"
• recursive (boolean) - Include files from all subfolders
• search (string) - Search query using the built-in search engine

Example:

<ul>
    #for(let file of docly.getFiles(request.folderpath)) {#
    <li>
        <!-- file.Url is already the encoded address the site serves -->
        <a href="#docly.htmlAttributeEncode(file.Url)#">
            #docly.htmlEncode(file.filename)#
        </a>
    </li>
    #}#
</ul>

Example 2:

<div>
    #for (let file of docly.getFiles('/')) {#
    <div>
        #file.filename# - File name (without .docly)<br />
        #file.Title# - Title (the document name)<br/>
        #file.file# - Always true for a file (false for a folder in getPages)<br/>
        #file.folderpath# - Folder path<br/>
        #file.filepath# - Path to the file from the site root<br/>
        #file.Url# - Encoded url the site serves the file at<br/>
        #file.opendoc# - Url that opens the document in the editor<br/>
        #file.FormName# - Schema name (string)<br/>
        #file.DoclyTypeId# - Document type ID (number)<br/>
        #file.Guid# - Document guid<br/>
        #file.CreatedTime# - DateTime when document was created<br/>
        #file.LastModified# - DateTime when document was last changed<br/>
        #file.Filesize# - File size in bytes<br/>

        <!-- Read any document field directly: -->
        #file.Property1# - One of your custom document fields<br />
    </div>
    #}#
</div>

<!-- Tags and LastModifiedBy are only included with mode: "Full" -->
#for (let file of docly.getFiles('/', { mode: "Full" })) {#
    #file.LastModifiedBy# - Username (email) of who last changed the document<br/>
#}#

<div>
    #for (let file of docly.getFiles('/', { name: "*.pdf" })) {#
        ... only pdf files will be listed ...
    #}#
</div>

<div>
    #for (let file of docly.getFiles('/', { name: "*.pdf", depth: 2 })) {#
        ... pdf files will be listed going down 2 extra levels of sub folders ...
    #}#
</div>

getFolders(path, [options])

Same options as getFiles. Folders have their own fields:

#for(let folder of docly.getFolders(request.folderpath)) {#
<div>
    #folder.Name# - folder name<br />
    #folder.Url# - folder url<br />
    #folder.Path# - full path to the folder<br/>
    #folder.DoclyId# - folder id (number)<br/>
    #folder.Guid# - folder guid<br/>
    #folder.Created# - DateTime when the folder was created<br/>
    #folder.LastModified# - DateTime when the folder was last changed<br/>
    #folder.Size# - folder size in bytes<br/>
    <!-- Read any folder property fields directly: -->
    #folder.Property1# - One of your custom document fields<br />
</div>
#}#

<!-- Count is only present when you ask for it: -->
#for(let folder of docly.getFolders('/', { includeCounters: true })) {#
    #folder.Name# holds #folder.Count# documents<br />
#}#

Example - Listing folders and files (with sorting)

To be able to sort folders you must first set a folder schema type (right click folder and click properties, select type then enter value in setting tab).

<!-- In the example below we are sorting on a field called "Order" for folders and documents. You will have to setup this yourself in your schemas too. -->
<div>
#for(let folder of docly.sort(docly.getFolders(request.folderpath), 'Order')) {#
    <div>
        Folder: #folder.Name#
        Image: <img src="#docly.linkImage(folder, folder.Image)#" title="Test" />
    </div>
    <ul>
        #for(let file of docly.sort(docly.getFiles(request.folderpath + '/' + folder.Name), 'Order', 'CInt')) {#
        <li>
            <img src="#docly.linkImage(file, file.Logo, 100, 100, 0, file.MyTitle + '.jpg')#" alt="#docly.htmlAttributeEncode(file.MyTitle)#" />
            <a href="#docly.htmlAttributeEncode(file.Url)#">
                #docly.htmlEncode(file.filename)#
            </a>
        </li>
        #}#
    </ul>
#}#
</div>

For folders using the schema "Published folder" sort by the field "SortOrder":

.... #for (let folder of docly.sort(docly.getFolders('MyFolder'), 'SortOrder', 'CInt')) {# ...

Example - List documents from multiple folders

Join contents of multiple folders:

<div>
    #{
        // Join the contents of two folders, sort by the "Published" field and take the first 5
        let list = docly.getFiles("Folder1").concat(docly.getFiles("Folder2"));
        list = docly.sortDesc(list, "Published");
        list = docly.take(list, 5);
    }#

    #for(let item of list) {#
        #docly.htmlEncode(item.Title)# - document name<br />
        ...
    #}#
</div>

The example sorts the joined list by a custom field called "Published" before taking the first five.

Related resources