FileUtils icon

FileUtils

File system operations utility

Overview

The node provides a set of file system utility operations, including listing directories, finding files, reading and writing files, and searching content within files. The Search Content operation specifically allows users to search for text or regex patterns inside a specified file, returning matching results.

This node is beneficial in scenarios where you need to automate file content inspection, such as:

  • Searching logs for error messages.
  • Extracting specific data from configuration files.
  • Automating content validation or auditing tasks.

For example, you could use the Search Content operation to scan a log file for occurrences of the word "ERROR" or a regex pattern matching IP addresses.

Properties

Name Meaning
File Path Path to the file to search within. Required if input source is "File Path". Optional metadata otherwise.
Search Pattern The text string or regular expression pattern to search for inside the file. (Required)
Use Regular Expression Whether to treat the search pattern as a regex (true) or plain text (false).

Output

The output JSON contains a field named results which is an array of matches found in the file content based on the search pattern. Each element in this array represents one match result.

If no matches are found, the output will be empty (no items pushed).

The node does not output binary data for this operation.

Example output structure:

{
  "results": [
    "matched line or content snippet 1",
    "matched line or content snippet 2"
  ]
}

Dependencies

  • Requires access to the local file system to read the specified file.
  • No external API keys or services are needed.
  • The node depends on internal helper functions to perform the grep-like search operation.

Troubleshooting

  • Error: File path is required
    This occurs if the "File Path" property is empty when using "File Path" as the input source. Ensure the file path is correctly provided.

  • No results returned
    If the search pattern does not match any content, the output will be empty. Verify the pattern and whether "Use Regular Expression" is enabled appropriately.

  • Invalid regular expression
    If "Use Regular Expression" is enabled but the pattern is malformed, the node may throw an error. Validate your regex syntax before running.

  • File not accessible or permission denied
    Make sure the n8n process has read permissions for the target file path.

Links and References

Discussion