Overview
This node performs various file system operations on files and directories. It is useful for automating common filesystem tasks such as cleaning up empty folders, fixing filenames that may cause compatibility issues (especially on Windows), deleting files based on patterns, moving files between directories, flattening directory structures by moving all files to a root folder, and renaming files or directories with pattern matching.
Practical examples include:
- Cleaning up leftover empty folders after file processing.
- Renaming files to remove invalid characters for Windows compatibility.
- Deleting temporary or backup files matching certain patterns.
- Moving files from one directory to another based on filename patterns.
- Flattening nested folders into a single directory for easier access.
- Renaming files or directories using regex-based find-and-replace.
Properties
| Name | Meaning |
|---|---|
| Directory Path | The path of the directory where the operation will be performed. |
| Recursive | Whether to process subdirectories recursively (true/false). |
| Only Directories | When fixing file names, whether to only fix directory names and skip files (true/false). |
Output
The output JSON structure varies depending on the selected operation:
- Fix File Names: Returns an object under
resultcontaining details about the fixed file and directory names. - Clean Empty Directories: Returns a success flag (
success: true) indicating completion. - Delete Files: Returns a result object summarizing deleted files and directories.
- Move Files: Returns a result object describing moved or renamed files/directories.
- Flatten Directory: Returns a result object describing the flattening outcome.
- Rename: Returns details about the rename operation including:
beforeRename: original source pathpath: new path after renameparent: parent directory of the renamed itemname: basename of the renamed item
If an error occurs during execution and "Continue On Fail" is enabled, the output includes an error field with the error message.
No binary data output is produced by this node.
Dependencies
- Requires access to the local filesystem with appropriate read/write permissions.
- No external API keys or services are needed.
- Uses internal helper modules for each operation (e.g., cleanEmptyDirectories, fixFileNames).
- Node environment must support asynchronous filesystem operations.
Troubleshooting
Common Issues:
- Invalid or inaccessible directory paths can cause errors.
- Insufficient permissions to modify files or directories.
- Using recursive option on very large directory trees may lead to performance delays.
- Pattern syntax errors when specifying regex patterns for file matching.
Error Messages:
- Errors related to file or directory not found usually indicate incorrect paths.
- Permission denied errors suggest running n8n with sufficient privileges.
- Regex pattern errors should be resolved by validating the pattern syntax.
To resolve errors, verify input parameters, ensure correct directory paths, and check user permissions.