Skip to content

datasource.renameFile ^v2.7.191 ​

Renames or moves a file.

js
datasource.renameFile(fileName, newName, overwrite)

Parameters ​

ParameterTypeDescription
fileNamestringThe file's current path.
newNamestringThe file's new path. A different folder moves the file.
overwritebooleanOptional. true to replace a file already at newName. Defaults to false.

Returns ​

boolean

true 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");
}