Rename Library File
Controlled node
Overview
The Rename Library File node allows you to programmatically rename files stored in your project's library. This is useful for organizing files, updating naming conventions, or dynamically renaming files based on workflow logic.
When triggered, the node takes a file reference and a new name, then updates the file's metadata in the library. The node outputs the updated file object with the new name upon success, or an error object if the operation fails.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| Run | Event | Triggers the rename operation. | - |
| File | FileSource | The file to rename. Accepts a single file object or an array (first item is used). Must contain a valid file id. | - |
| Name | Text | The new name for the file. Must be a non-empty string. The file extension should be included if you want to preserve it. | - |
Outputs
| Output | Type | Description |
|---|---|---|
| Done | Event | Fires when the rename operation completes, regardless of success or failure. |
| File | Data | On success: the updated file object containing the new name and metadata. On failure: an object with an error property containing the error message. |
Runtime Behavior
When the Run event fires, the node performs the following actions:
- Validation: Checks that both
fileandnameinputs are provided and valid. Thenamemust be a non-empty string. - Project Context: Retrieves the current
projectIdfrom the workflow runtime context. - File Resolution: If the
fileinput is an array, it selects the first element. Validates that the file object contains anidproperty. - Rename Operation: Calls the library system to rename the file using
librarySystem.renameFile(projectId, file.id, newName). - Output:
- On success: Outputs the renamed file object to the
fileoutput and firesdone. - On failure: Outputs an error object
{error: 'Error renaming file: <message>'}to thefileoutput and firesdone.
- On success: Outputs the renamed file object to the
When providing the new name, ensure you include the file extension (e.g., .pdf, .txt) if you want to preserve the file type. The node does not automatically append extensions.
If the file cannot be renamed (e.g., permissions issues, file not found, or invalid name), the node will output an error object to the file socket rather than throwing a workflow error. Always check the output structure when handling errors.
Example
Here's an example of how to use the Rename Library File node in a workflow:
- Get Library Files node outputs a list of files from a folder.
- For Each node iterates over the files.
- Text node constructs a new name using template variables (e.g.,
"Report_{{date}}_{{element.name}}"), whereelementis the current file from the For Each loop. - Rename Library File node receives:
file: The current file object from the loopname: The constructed new name from the Text noderun: Triggered by the For Each loop event
- Assert node checks the
fileoutput to verify the rename was successful (checking that the output doesn't contain anerrorproperty).
[Get Library Files]
↓ (files list)
[For Each] → [Text: "Report_{{date}}_{{element.name}}"]
↓ (element) ↓ (newName)
[Rename Library File] ←───────┘
↓ (file output)
[Assert: check no error]
↓
[Done]