File Manager

Manage files and folders on disk

Overview

This node, named "File Manager," provides a variety of file and folder management operations on the local disk. It is useful for automating tasks such as creating files or directories, copying or moving files, compressing or extracting archives, reading or writing file contents, changing permissions, listing directory contents, checking existence, retrieving metadata, searching files by pattern, and removing files or folders.

Typical use cases include:

  • Automating backup processes by compressing folders.
  • Managing file system structure by creating, moving, or renaming files and folders.
  • Reading or updating configuration files during workflows.
  • Searching for specific files matching patterns within directories.
  • Cleaning up temporary files or folders.

For example, you could use this node to create a new folder, copy files into it, compress the folder into a tar.gz archive, and then move the archive to a backup location.

Properties

Name Meaning
Operation The file operation to perform. Options: Append, Change Permissions, Compress, Copy, Create, Exists, Extract, List, Metadata, Move, Read, Remove, Rename, Search, Write.
Source Path Path of the source file or folder (used in operations like create, copy, move, compress, extract, rename, remove).
Destination Path Target path for copy, move, rename, compress, and extract operations.
Recursive Whether to delete folders recursively (only for Remove operation).
Target Path Path of the file or folder to operate on (used in read, write, append, list, exists, metadata, chmod operations).
Data Content to write or append to the file (used in write and append operations).
Encoding File encoding for reading or writing files (default is utf8).
Mode Unix permission bits for changing file/folder permissions (e.g., 644) (used in Change Permissions operation).
Base Path Directory to start searching from (used in Search operation).
Pattern Regex pattern to match file paths (used in Search operation).

Output

The output JSON structure varies depending on the operation performed:

  • For Create, Copy, Move, Rename, Compress, Extract, and Remove operations:

    • operation: The operation name.
    • success: Boolean indicating success.
    • sourcePath: The source path used.
    • destinationPath: The destination path used (if applicable).
  • For Read:

    • data: The content of the file read as a string.
    • targetPath: The path of the file read.
    • operation, success.
  • For Write and Append:

    • targetPath: The path of the file written/appended.
    • operation, success.
  • For Change Permissions (chmod):

    • targetPath: The path of the file/folder.
    • mode: The permission mode set.
    • operation, success.
  • For List:

    • list: Array of filenames in the directory.
    • targetPath: The directory path listed.
    • operation, success.
  • For Exists:

    • exists: Boolean indicating if the file/folder exists.
    • targetPath: The path checked.
    • operation, success.
  • For Metadata:

    • size: File size in bytes.
    • mtime: Last modification time.
    • atime: Last access time.
    • isDirectory: Boolean indicating if path is a directory.
    • isFile: Boolean indicating if path is a file.
    • targetPath: The path queried.
    • operation, success.
  • For Search:

    • paths: Array of file paths matching the regex pattern.
    • basePath: The base directory searched.
    • pattern: The regex pattern used.
    • operation, success.

The node does not output binary data directly; all file contents are handled as strings with specified encoding.

Dependencies

  • Requires access to the local filesystem where n8n is running.
  • Uses Node.js built-in modules: fs (filesystem), path, child_process (for spawning tar commands), and zlib (for gzip decompression).
  • For compression and extraction, the system must have the tar command available.
  • No external API keys or credentials are required.

Troubleshooting

  • Permission errors: Operations may fail if the n8n process lacks sufficient permissions to read/write/delete the specified paths. Ensure proper filesystem permissions.
  • Non-existent paths: Trying to operate on files or folders that do not exist will cause errors. Use the "Exists" operation to check before proceeding.
  • Invalid paths: Paths must be valid and accessible. Relative paths are resolved based on the n8n process working directory.
  • Compression/Extraction failures: These rely on the tar command. If tar is missing or fails, errors like tar exited with code X will occur.
  • Regex syntax errors: In the Search operation, invalid regex patterns will throw errors. Validate regex before use.
  • Recursive deletion caution: Removing folders recursively deletes all contents without recovery. Use carefully.

If the node throws a generic error about an unknown operation, verify that the operation parameter is correctly set.

Links and References

Discussion