Docly Developers
Function API only Updated 17 Oct 2026

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.

See also Path traversal

Parameters

filePathstringrequired

Entire absolute path for file to rename.

newNamestringrequired

New name without path.

Returns

true when the file was renamed (also when the name is unchanged).

Throws if the path or the new name is empty, the file is not found, the new name is not a valid file name, another file in the folder already has that name, or the new name ends with .hash or .js (not allowed from scripts). A target that only exists in the app (publish template) the site runs from throws error 110: the app's files are shared by every site on it and can't be changed from a site.

The call runs as the user who published the site, not as the visitor. Check the visitor's own rights with allowModify before you change anything on their behalf.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// Renames file in specified folder, file stays in the same folder
docly.renameFile("Folder/File1.json", "File2.json");

// Example with error handling
try {
    docly.renameFile("Projects/Report.json", "RenamedReport.json");
    console.log("File renamed successfully");
} catch (e) {
    // Throws if path or name is empty, the file does not exist, the name is invalid or taken,
    // or the new name ends with .hash or .js
    console.log("Failed to rename file: " + e);
}