datasource.renameFile ^v2.7.191
Renames or moves a file.
js
datasource.renameFile(fileName, newName, overwrite)Parameters
| Parameter | Type | Description |
|---|---|---|
fileName | string | The file's current path. |
newName | string | The file's new path. A different folder moves the file. |
overwrite | boolean | Optional. true to replace a file already at newName. Defaults to false. |
Returns
booleantrue when the file was renamed. false when a path is invalid, the file doesn't exist, or a file is already at newName and overwrite isn't true.
Examples
js
// Simple rename in the same directory
datasource.renameFile("report.txt", "report_final.txt");
// Move a file to a different directory
datasource.renameFile("input/data.csv", "archive/data_2024.csv");
// Rename and overwrite if the target exists
datasource.renameFile("temp/output.json", "results/output.json", true);
// Check if rename was successful
const success = datasource.renameFile("old.txt", "new.txt");
if (!success) {
console.log("Failed to rename file");
}