File Manager

Manage files and folders on disk

Overview

This node provides file system management capabilities, allowing users to perform various operations on files and folders directly on disk. The Search operation specifically enables recursively searching for files or directories starting from a specified base directory, matching their paths against a user-defined regular expression pattern.

Common scenarios where this node is beneficial include:

  • Finding all files of a certain type (e.g., all .txt files) within a directory tree.
  • Locating files or folders whose names match complex patterns.
  • Automating workflows that require dynamic discovery of files before processing them further.

For example, you could use the Search operation to find all log files in /var/logs by specifying the base path as /var/logs and the pattern as .*\.log$. The node will return all matching file paths found under that directory and its subdirectories.

Properties

Name Meaning
Source Path Path of the source file or folder (not used in Search operation but required generally).
Base Path Directory path from which the search starts.
Pattern Regular expression pattern to match file paths against during the search.

Output

The output JSON contains the following fields relevant to the Search operation:

  • operation: The string "search".
  • success: Boolean indicating if the operation succeeded (true).
  • basePath: The directory path where the search started.
  • pattern: The regex pattern used for matching file paths.
  • paths: An array of strings, each being a full path to a file or folder that matched the regex pattern.

Example output JSON snippet:

{
  "operation": "search",
  "success": true,
  "basePath": "/start/path",
  "pattern": ".*\\.txt$",
  "paths": [
    "/start/path/file1.txt",
    "/start/path/subfolder/file2.txt"
  ]
}

No binary data is produced by this operation.

Dependencies

  • Node.js built-in modules: fs (filesystem), path.
  • No external API keys or services are required.
  • The node runs commands using child processes only for other operations; Search uses pure Node.js filesystem APIs.

Troubleshooting

  • Common issues:

    • Invalid or inaccessible base path: If the base directory does not exist or the node lacks permissions, the search will fail.
    • Invalid regex pattern: A malformed regex pattern will cause an error when constructing the RegExp object.
    • Large directory trees: Searching very large directory structures may take significant time or resources.
  • Error messages:

    • Errors related to reading directories or files usually indicate permission issues or non-existent paths.
    • Regex errors will typically mention invalid regular expressions.
  • Resolutions:

    • Ensure the base path exists and the n8n process has read permissions.
    • Validate regex patterns before running the node.
    • Limit the scope of the search with more specific base paths or patterns to improve performance.

Links and References

Discussion