Delete File/Dir
Deletes the file/directory from specified path
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
if ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- Path - The path of the file/directory that will be deleted.
Options
- Recursive - States that files/folders will be deleted recursively or not.
- Name Filter - Optional filter pattern for matching specific files (e.g.,
*.txt,*.log)
How It Works
The Delete File/Dir node removes files or directories through the following process:
- Validates that the path is not empty
- Checks if the specified path exists
- If a name filter is provided:
- Uses filepath.Glob to match files based on the filter pattern
- Deletes all matched files/directories
- If no name filter is provided:
- Deletes the specified file or directory directly
- Uses recursive deletion (RemoveAll) if Recursive option is enabled
- Uses single-level deletion (Remove) if Recursive is disabled
Requirements
- Valid path to an existing file or directory
- Write/delete permissions on the target file or directory
- For recursive deletion, permissions on all subdirectories and files
- Path must exist (node will fail if path is invalid)
Error Handling
| Error Code | Description |
|---|---|
Core.FileSystem.Delete.ErrOnCreate | Node configuration parsing failed |
Core.FileSystem.Delete.ErrOnMessage | Input message parsing failed |
Core.FileSystem.Delete.ErrPath | Path is empty |
Core.FileSystem.Delete.ErrInvalidPath | The specified path does not exist |
Core.FileSystem.Delete.ErrDelete | Deletion failed (permission denied, in use, or I/O error) |
Usage Examples
Example 1: Delete a Single File
Delete a temporary file after processing:
{
"path": "C:\\Temp\\processing_temp.xlsx"
}
Configuration:
- Recursive: false
- Name Filter: (empty)
Example 2: Delete Directory Recursively
Delete an entire directory with all its contents:
{
"path": "D:\\Archive\\OldReports"
}
Configuration:
- Recursive: true
This removes the directory and all files and subdirectories within it.
Example 3: Delete Files by Pattern
Delete all log files older than a certain period in a directory:
{
"path": "C:\\Logs\\",
"nameFilter": "*.log"
}
Configuration:
- Recursive: true
- Name Filter:
*.log
This deletes all .log files in the Logs directory.
Usage Notes
- When Recursive is false, only empty directories can be deleted; directories with contents will fail
- When Recursive is true, the entire directory tree is deleted, including all files and subdirectories
- The Name Filter field supports glob patterns (e.g.,
*.txt,report_*.csv) - Name Filter is appended to the path, so ensure the path ends with a separator if filtering files in a directory
- Files currently in use by other processes cannot be deleted and will cause an error
- Deletion is permanent and cannot be undone
- The node was enhanced to support Name Filter for backward compatibility with older versions
Tips
- Always use Path Exists node before deletion to verify the path exists
- Enable Continue On Error when deleting files that might not exist
- Use Name Filter to delete specific file types without affecting others
- Test deletion operations on non-critical data first
- Consider moving files to a trash/archive folder instead of permanent deletion
- For log rotation, combine with List Directory to identify old files before deletion
- Be extremely careful with recursive deletion on important directories
- Verify the path is correct before executing to avoid accidental data loss
Related Nodes
- Path Exists - Verify file/directory exists before deletion
- List Directory - List files to identify what will be deleted
- Move File/Dir - Move files to archive instead of deleting
- Create File/Dir - Create directories after cleanup