FileOperate icon

FileOperate

File system operations for files and directories

Rename

AI-generated

Overview

This node operation performs renaming of files or directories based on specified source and target paths. It supports pattern matching with regular expressions to selectively rename parts of the target path using a replacement string. It also includes a stage test mode to simulate the renaming without making actual changes, which is useful for verifying the renaming logic before execution.

Use Case Examples

  1. Renaming a file from 'oldname.txt' to 'newname.txt' by specifying source and target paths.
  2. Using a regular expression pattern to rename files by replacing parts of their names, e.g., changing all '.txt' extensions to '.md'.
  3. Simulating the rename operation to preview changes without modifying any files.

Properties

Name Meaning
Source Path The original file or directory path to be renamed.
Target Path The new file or directory path after renaming.
Pattern Optional regular expression pattern to match parts of the Target Path for selective renaming.
Replacement String to replace the matched pattern in the Target Path.
Stage Test If true, simulates the rename operation without actually performing it, allowing preview of changes.

Output

JSON

  • 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 new name of the file or directory after renaming.

Dependencies

  • Node.js 'path' module for path manipulations

Troubleshooting

  • If the rename operation fails, ensure the source path exists and the target path is valid and accessible.
  • Regular expression patterns must be valid; invalid patterns may cause errors or unexpected behavior.
  • If 'Stage Test' is enabled, no actual renaming occurs; disable it to perform real renaming.

Discussion