Delete File

Delete files or directories

Overview

This node deletes files or directories from the filesystem based on a specified path. It supports deleting only files, only directories, or automatically detecting the type to delete accordingly. The node includes safety features such as requiring explicit confirmation before deletion, limiting maximum file size for deletion, backing up files before removal, and options to skip errors if the target does not exist.

Common scenarios where this node is useful include:

  • Cleaning up temporary files or folders after processing.
  • Automating removal of outdated logs or data exports.
  • Managing disk space by deleting large files exceeding a certain size.
  • Safely removing directories with recursive deletion enabled.

For example, you could configure it to delete a specific log file only if it is under 100 MB, require typing "DELETE" to confirm, and create a backup copy before deletion.

Properties

Name Meaning
Path The full path to the file or directory to delete.
Delete Mode What type of item to delete:
• File Only — delete only if the path is a file (error if directory).
• Directory Only — delete only if the path is a directory (error if file).
• Auto Detect — delete file or directory automatically.
Safety Options Collection of safety-related settings:
• Recursive Directory Deletion — whether to delete directories recursively with all contents.
• Require Confirmation — require explicit confirmation text before deletion.
• Confirmation Text — the exact text that must be provided to confirm deletion.
• Max File Size (MB) — maximum allowed file size to delete; 0 means no limit.
• Backup Before Delete — whether to create a backup copy before deleting.
• Backup Directory — directory to store backups; uses system temp if empty.
• Skip if Not Exists — skip deletion without error if the path does not exist.

Output

The node outputs an array of JSON objects corresponding to each input item processed. Each output object contains:

  • success (boolean): Whether the operation succeeded.
  • skipped (boolean, optional): True if the deletion was skipped because the file/directory did not exist and skipping was enabled.
  • message (string, optional): Informational message when skipping.
  • path (string): The resolved absolute path of the deleted/skipped item.
  • deleted (boolean): True if the item was deleted.
  • name (string): The base name of the deleted file or directory.
  • type (string): Either "file" or "directory".
  • size (number): Size in bytes of the deleted file or directory.
  • sizeHuman (string): Human-readable file size (e.g., "1.2 MB").
  • deletionTime (number): Time taken in milliseconds to perform the deletion.
  • deletedAt (string): ISO timestamp of when the deletion occurred.
  • backupPath (string, optional): Path to the backup file if backup was created.

If the node encounters an error and "Continue On Fail" is enabled, it outputs an object with success: false, an error message, and the attempted path.

The node does not output binary data.

Dependencies

  • Requires access to the local filesystem where the n8n instance runs.
  • Uses Node.js built-in modules: fs (filesystem), path.
  • No external API or service dependencies.
  • No special environment variables required.
  • If backup is enabled, the node writes backup files to either a user-specified directory or the system temporary directory.

Troubleshooting

  • File or directory not found: If the specified path does not exist and "Skip if Not Exists" is false, the node throws an error. To avoid failure, enable skipping or verify the path.
  • Wrong delete mode: Selecting "File Only" but providing a directory path (or vice versa) causes an error. Ensure the delete mode matches the target type or use "Auto Detect".
  • Confirmation missing or incorrect: If "Require Confirmation" is enabled, the exact confirmation text must be provided; otherwise, deletion is blocked.
  • File size exceeds limit: If a max file size is set, files larger than this limit will cause an error.
  • Backup of directories not supported: Attempting to back up a directory before deletion results in an error since directory backup is not implemented.
  • Recursive deletion disabled for directories: Trying to delete a non-empty directory without enabling recursive deletion will fail.
  • Permission issues: Lack of filesystem permissions to read, write, or delete the target path will cause errors.
  • Path resolution: Relative paths are resolved to absolute paths; ensure correct path formatting.

Links and References

Discussion