Overview
This node performs various file system operations on files and directories, including renaming files or directories with pattern matching. The "Rename" operation specifically allows you to rename a file or directory from a given source path to a target path, optionally using a regular expression pattern to modify the target path name.
Common scenarios for the Rename operation include:
- Renaming files or folders in bulk based on naming patterns.
- Adjusting file or directory names to conform to specific naming conventions.
- Simulating renaming actions before applying them to verify changes.
For example, you might rename a file /data/oldname.txt to /data/newname.txt, or use a regex pattern to replace parts of the target path dynamically.
Properties
| Name | Meaning |
|---|---|
| Source Path | The full path of the file or directory you want to rename. |
| Target Path | The desired new path for the file or directory after renaming. |
| Pattern | (Optional) A regular expression to match part of the Target Path for replacement. |
| Replacement | (Optional) The string to replace the matched pattern in the Target Path. |
| Stage Test | If enabled, simulates the rename operation without actually performing it (dry run). |
Output
The output JSON object contains information about the rename operation:
beforeRename: The original source path before renaming.path: The new path after renaming.parent: The parent directory of the renamed file or directory.name: The base name (file or directory name) after renaming.
If the rename did not occur (e.g., no changes were made), the output will simply return the input JSON unchanged.
No binary data is produced by this operation.
Dependencies
- This node relies on Node.js core modules such as
path. - It uses internal helper functions for file system operations bundled within the node's dependencies.
- No external API keys or services are required.
- The node requires appropriate file system permissions to read, write, and rename files/directories on the host machine.
Troubleshooting
Common issues:
- Invalid source or target paths can cause errors; ensure paths exist and are accessible.
- Incorrect regular expressions in the Pattern property may lead to unexpected renaming results or no changes.
- Insufficient file system permissions can prevent renaming.
- Using Stage Test disables actual renaming, so no changes will be applied.
Error messages:
- Errors related to file access or permission denied indicate the node cannot modify the specified files/directories.
- Regex syntax errors in the Pattern property will cause failures; validate your regex before use.
- If the node throws an error but Continue On Fail is enabled, the error message will appear in the output under the
errorfield.
To resolve these issues:
- Verify all paths and permissions.
- Test regex patterns separately.
- Disable Stage Test to apply changes.
- Use Continue On Fail cautiously to handle errors gracefully.
Links and References
- Node.js path module documentation
- Regular Expressions (MDN)
- n8n Documentation on File System Nodes (for general usage context)