Docly Developers
Section51 pages

Filesystem functions

Functions to link files and images from Docly to your web content.

getFiles(path, options?)Gets a list of files from folder / optionally recursively from subfolders.getFolder(path)Returns information about a folder by given path.fileExists(filePath)Checks whether a file exists in the site, including files the site inherits from the app (publish template) it runs from. Available in…folderExists(path)Checks whether a folder exists in the site, including folders the site inherits from the app (publish template) it runs from. Only…createFolder(folderPath, folderType?)Creates a folder from the specified path, including any missing parent folders. Folders that already exist are left as they are.deleteFile(filePath)Deletes a specified file. The call runs as the user who published the site, not as the visitor. Check the visitor's own rights with…deleteFolder(folderPath)Deletes a specified folder.getFolderProps(folderPath)Get a specified folders current properties.saveFolderProps(path, values, options?)Saves the properties of a folder — the data in its folder properties document. The call runs as the user who published the site, not as the…validateFilename(filename)Validates that a filename contains only allowed characters.extractBase64Images(html)Extracts base64-encoded images from an HTML string and replaces each one with a Content ID (cid:) reference, the way images are referenced…extractAndEmbedBase64Images(filePath, propertyFilter?)This function extracts images encoded in base64 from HTML properties of a document. It then converts these images to a more…createZip(content)Creates a ZIP-file and adds specified files and folders to it.getEmbeddedFile(path, id)Get bytes of an embedded file (image or file upload) in a specific document.Include(path, template?)Include a file or template into another page. include2 is an internal variant used while rendering included documents — do not call it…saveEmbeddedFolderFile(folderPath, embeddedFilename, data)Saves an embedded file to the properties document of an existing folder. The folder must already have a properties document — create one…allowRead(path, username?)Checks whether the logged-in visitor, or a given user, may open the specified file or folder in Docly. For a folder this is Browse access…allowModify(path, username?)Checks whether the logged-in visitor, or a given user, may modify the specified file or folder in Docly. Only meaningful on sites with…allowVisit(path, username?)Checks whether the logged-in visitor, or a given user, has website (Visit) access to the specified file or folder. Only meaningful on sites…getEmbeddedFileSize(path, id)Get the size of an embedded file (image or file upload) in a specific document.getFolders(path, options?)Gets a list of all subfolders below a specific folder.getEmbeddedTextFile(path, id, encoding?)Get the text content of an embedded file in a specific document.getEmbeddedFolderFile(folderPath, embeddedFilename)Retrieves embedded file content from a folder's property file (.docly) by extracting and decoding the specified file data.getFile(path, includeMetadata?)Gets a single file with its data and metadata.getJson(filepath)Loads a document and returns its stored values as an object. Works on any document — a .json code file, or a schema document (you get its…linkFile(fileObject?, embeddedId, filename?)Creates the link to an embedded file within a document. Available in every #JS context — display templates, .hash pages, master pages and…listFiles(path, options?)The fastest function to retrieve a list of files from a specific path.listFolders(path, options?)The fastest function to retrieve a list of folders from a specific path.linkImage(fileObject?, embeddedId, width?, height?, mode?, filename?)Creates a link to an image within a document, building a WxHxM image URL. Available in every #JS context — display templates, .hash pages…Image scalingHow scaled image URLs work, which sizes a site accepts (images.sizePolicy), and the scaling modes.loadExcel(file, startCol?, startRow?, sheetNo?)Loads data from Excel file into an array of objects.Image output formatsDocly can deliver modern image formats (WebP / AVIF) with better compression via scaleImage and the site-wide default format.moveFile(filePath, toPath)Moves a file into another folder. The file keeps its name — use renameFile to change the name.moveFolder(folderPath, destinationPath)Moves a folder to a new location within your site.renameFile(filePath, newName)Renames an existing file while keeping it in the same folder. The file is identified by its full path, and only the filename is changed.saveEmbeddedFile(filePath, embeddedId, data)Saves an embedded file to an existing Docly document. Note that embedded files that are not referenced by a field in the document will be…renameFolder(folderPath, newName)Renames an existing folder without moving it. The folder remains in its current parent directory but receives a new name.patchFile(path, patch)Merges the given properties into an existing document and saves it. The merge is shallow: each top-level property in the patch replaces the…saveFile(filePath, data, options?)Saves a file to a Docly document according to specified schema. Overwrites if it already exists.saveJson(filePath, data, ensurePath?)Saves data as a JSON file to Docly with specified content stringified to JSON format. This function is ideal for storing structured data in…logJson(filePath, data)Appends an entry to a JSON log file — a file holding a JSON array — and creates the file if it does not exist. If the path ends with '/'…unlockFolder(path, encryptionKey)Unlocks an encrypted folder for the current request. After unlocking, file operations (getFile, saveFile, downloadEmbedded…getTags(path)Returns the tags stored on a document. Tags share their storage with the full text search index, so they are always stored — and returned —…addTag(path, tag)Adds a tag to a document without touching the tags that are already there. Only the missing tag is written, so two scripts tagging the same…removeTag(path, tag)Removes a tag from a document without touching its other tags. The counterpart of [addTag](/JavaScript/Filesystem-functions/addTag), and…getAllTags(path, options?)Returns every distinct tag in use in a folder — the list you need to fill a tag picker, an autocomplete or a filter menu. The values it…getFilenames(path, options?)Returns the names of the files in a folder — a lighter alternative to listFiles when the names are all you need. Only the folder itself is…getPages(path, options?)Returns the pages in a folder, for building menus and listings: one entry for each subfolder that has an index page, followed by the files…load(file)Loads a file from the site, runs the #JS code it contains and returns the result as text.drive.getFiles(path, options?)Lists every file below a folder the way it appears on a mapped Docly drive — with the file names and extensions a drive or an export uses…drive.getFile(path)Returns the content of a file the way it appears on a mapped Docly drive. Called as drive.getFile(...).