FileOperate icon

FileOperate

File system operations for files and directories

Overview

The node performs various file system operations on files and directories. Specifically, the "Flatten Directory" operation restructures a directory by moving all files from nested subdirectories into the root directory, effectively removing the hierarchical folder structure within that directory.

This operation is useful when you want to simplify a complex directory tree into a single folder containing all files, for example:

  • Consolidating scattered files for easier batch processing.
  • Preparing files for upload or archival where a flat structure is preferred.
  • Cleaning up project folders by removing unnecessary subfolders.

Properties

Name Meaning
Directory Path The path of the directory whose structure will be flattened by moving all files to its root.

Output

The output JSON contains the original input data merged with a result field. This result field holds the outcome of the flattening operation, which typically includes details such as the number of files moved or any relevant status messages.

No binary data output is produced by this operation.

Example output snippet:

{
  "inputProperty1": "value1",
  "result": {
    "filesMoved": 42,
    "status": "success"
  }
}

Dependencies

  • The node relies on an internal utility function to perform the flattening logic.
  • No external API keys or services are required.
  • It operates on local file system paths accessible by the n8n runtime environment.
  • Proper permissions to read/write/move files in the specified directory are necessary.

Troubleshooting

  • Common issues:

    • Invalid or inaccessible directory path: Ensure the provided directory path exists and n8n has permission to access it.
    • Files locked by other processes may prevent moving.
    • Insufficient disk space in the target directory (root directory) could cause failures.
  • Error messages:

    • Errors related to file system access (e.g., "ENOENT", "EACCES") indicate missing directories or permission problems.
    • If the node throws errors about invalid parameters, verify that the "Directory Path" is correctly set and not empty.
  • Resolution tips:

    • Verify directory paths and permissions before running.
    • Run the node with test data to simulate the operation if supported.
    • Check logs for detailed error information.

Links and References

Discussion