---
url: /process-functions/datasource-renameFile.md
description: Renames or moves a file within the MODLR file system.
---

# datasource.renameFile&#x20;

Renames or moves a file within the MODLR file system. Both the source and destination paths must be within the root directory of the datasource.

```js
datasource.renameFile(fileName, newName, overwrite)
```

#### Parameters

* `fileName` - The current name and file path of the file in the MODLR file system. File path can be found in the filesystem page.
* `newName` - The new name and file path for the file.
* `overwrite` (optional) - If `true`, overwrites the target file if it already exists. If `false` or omitted, returns an error if the target file exists. Defaults to `false`.

#### Returns

* `boolean` - Returns `true` if the file was renamed successfully, `false` if:
  * The source file path is invalid
  * The source file does not exist
  * The new file path is invalid
  * The target file already exists (when `overwrite` is `false`)
  * The target file could not be deleted (when `overwrite` is `true`)
  * The rename operation failed

#### Example

```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
let success = datasource.renameFile("old.txt", "new.txt");
if (!success) {
    console.log("Failed to rename file");
}
```
