getFolders(path, [options])
Gets a list of all subfolders below a specific folder.
Parameters
pathstringrequiredAbsolute path to the folder which you want to list sub folders for.
optionsobjectoptionalnamestringEnter a wildcard of folders to retrieve, default is "*"
depthnumberHow many extra levels of subfolders, default is 0
recursiveboolGet sub folders recursively, default false.
propertiesboolGet with folder properties, default true.
Use false for faster execution without this extra information.
filterobject | functionFilter items based on their properties. Accepts either:
- Object with key-value pairs for exact matching (e.g. { "Status": "active" })
- Function that receives each folder and returns true/false (e.g. x => x.Size > 1000000 && x.Status == "active")
fieldscsv | array | objectSpecify fields to retrieve via:
- CSV string (e.g. "Name,Url")
- Array of strings (e.g. ["Name","Url"])
- Object map for renaming (e.g. {"title":"Name"})
includeCountersboolAdd a Count field to each folder with the number of documents it contains, default false. Deleted documents and the folder properties file are not counted. Returns the same number as listFolders.
accessstringWhose access the list follows. Leave it out for the default: the signed-in visitor in an API script, the publisher everywhere else. 'publisher' lists with the publisher's access in an API script too — use it when your script checks permissions itself, for example looking up a record anywhere in the site and then deciding from its own user registry. It is the publisher's access, not everything: folders the publisher is denied, # folders and tool folders are still left out. Any other value throws an error.
Returns
An array of folder objects. Every object carries Name, Url, Path, DoclyId, Guid, Created, LastModified and Size — the same names and date form getFolder uses for the fields they share. Count is added only when includeCounters is true. Unless you pass properties: false, the folder's own fields from its folder document are merged in first, so a custom field sharing one of the standard names above is overwritten by the standard value; Count is the exception and is left alone unless you ask for counters.
Folders whose name starts with # are never included, nor is anything below them, nor are folders the user has no website (Visit) access to. Access is checked for the signed-in visitor in an API script (/API/), and for the user who published the site everywhere else — on a page, and in an API script nobody is signed in to. Pass access: 'publisher' to check access for the publisher in an API script too — for an app that lets Docly handle sign-in and decides permissions itself (see Let Docly handle login, you handle the permissions). A page is cached and shared by every visitor, so on a page the list is the same for everyone. Properties of encrypted folders are left out — read them with getFolderProps after unlockFolder. An unknown folder gives an empty array; a path containing .. or a backslash gives null.
Example
#{
// Get the list of files
var list = docly.getFolders("Test files");
// The rest of the code just outputs the list in the demo field below
var json = JSON.stringify(list);
var formatted = docly.formatJson(json);
var html = formatted.replace(chr(13), "");
write(html);
}#[
{
"SortOrder": "1",
"DefaultContent": true,
"Accept": "",
"SpecifyCustomColumns": false,
"CustomColumns": [],
"CustomColumns_type": "CustomColumns",
"HideFilenameColumn": false,
"Expand": true,
"Packages": [],
"Packages_type": "Packages",
"ROWID": "4533b73f-c3b6-5e77-b143-222e43d122fb",
"OKCount": "0",
"PassedCount": "0",
"FailedCount": "0",
"TotalCount": "0",
"RemainCount": "0",
"Name": "Folder 1",
"Url": "/Test-files/Folder-1",
"DoclyId": 45972,
"Guid": "3rujvHyLOE-BkiQUUX5Kng",
"LastModified": "2025-01-30T10:16:35.5Z",
"Created": "2022-12-21T10:43:22.678Z",
"Size": 573,
"Path": "/Test files/Folder 1"
},
{
"Name": "Folder 2",
"Url": "/Test-files/Folder-2",
"DoclyId": 45973,
"Guid": "4KBt5OiHKUO_CMfMjN4rUA",
"LastModified": "2025-01-30T10:15:36.414Z",
"Created": "2022-12-21T10:43:25.408Z",
"Size": 228,
"Path": "/Test files/Folder 2"
},
{
"Name": "Folder 3",
"Url": "/Test-files/Folder-3",
"DoclyId": 45974,
"Guid": "rXOvQs861068dtNVyXh3nQ",
"LastModified": "2025-01-30T10:15:41.716Z",
"Created": "2022-12-21T10:43:27.684Z",
"Size": 228,
"Path": "/Test files/Folder 3"
}
]