GetFiles and Folders - examples Last updated: 06. Mar 2026

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

listFiles(path, wildcard)

Fastest way to retreive 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>
        <a href="#urlpathencode(trim(replace(replace(file.Url,' ','-'),'##','%23'),'/'))#">
            #file.Filename#
        </a>
    </li>
    #}#
</ul>

Example 2:

<div>
    #for (let file of docly.getFiles('/')) {#
    <div>
        #file.Filename# - Filename<br />
        #file.Title# - Title<br/>
        #file.IsFile# - Is file<br/>
        #file.FolderPath# - Folder path<br/>
        #file.Url# - Show file url<br/>
        #file.OpenDoc# - Edit doc url<br/>
        #file.DoclyType# - Document type name (string)<br/>
        #file.DoclyTypeId# - Document type ID (number)<br/>
        #file.FormName# - Schema type name (string)<br/>
        #file.FormId# - Schema type ID (number)<br/>
        #file.CreatedTime# - DateTime when document was created<br/>
        #file.LastModified# - DateTime when document was last changed<br/>
        #file.LastModifiedBy# - Username (email) of who last changed the document<br/>
        #file.DoclyId# - Folder or document Id<br/>
        #file.Filesize# - File size in bytes<br/>
        
        <!-- Read any page property fields directly: -->
        #file.Property1# - One of your custom document fields<br />
    </div>
    #}#
</div>

<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, wildcard, depth)

Same parameters as for "GetFiles".

#for(let folder of docly.getFolders(request.folderpath)) {#
<div>
    #folder.Name# - folder name<br />
    #folder.Url# - folder path<br />
    #folder.DoclyId# - folder id<br/>
    <!-- Read any folder property fields directly: -->
    #folder.Property1# - One of your custom document fields<br />
</div>
#}#

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="#folder.Url#/#folder.Image#" title="Test" />
    </div>
    <ul>
        #for(let file of docly.sort(docly.getFiles(request.folderpath + '/' + folder.Name), 'Order', 'CInt')) {#
        <li>
            <img src="#file.Url#/#file.Logo#/100x100x0/#file.MyTitle#.jpg" alt="#file.MyTitle#" />
            <a href="#urlpathencode(trim(replace(replace(file.Url,' ','-'), '##', '%23'), '/'))#">
                #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 >
    #let list = docly.getFiles("Folder1").concat(docly.getFiles("Folder2"))#          (Concat two folders)
    #let list = docly.sortDesc(list, "Publisert"))#                                   (Sort the list)
    #let list = docly.take(list, 5)#                                                  (Take 5 first items in list)
    
    #for(let item of list) {#
        #item.Name# - folder name<br />
        ...
    #}#
</div>

You would probably want to sort the list as well.