renameFile(filePath, newName) Last updated: 05. May 2026
API only function
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.
Parameters
| Name | Type | Description |
|---|---|---|
| filePath | string | Entire absolute path for file to rename. |
| newName | string | New name without path. |
Returns
Boolean, true if successful.
Throws an error if source path or new name is not specified, if the file is not found, or if the new name contains invalid characters.
Example
Code example (JS)
JS is normal JavaScript either 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 is empty, name is empty, file does not exist, or name contains invalid characters
console.log("Failed to rename file: " + e);
}