File Cleanup
AI-generatedOverview
This node deletes files in a specified directory whose names start with a given prefix. It is useful for cleaning up files that follow a naming convention, such as temporary files, logs, or batch-processed outputs that share a common filename prefix.
For example, if you have a folder containing files like temp_123.txt, temp_456.txt, and report_789.txt, and you specify the prefix temp_, this node will delete all files starting with temp_ but leave others untouched.
Properties
| Name | Meaning |
|---|---|
| File Starts With | The prefix of the file name to match for deletion. Must include an underscore and be at least 4 characters long (including the underscore). Example: temp_ |
| Directory | The path to the directory where files will be checked and deleted if they match the prefix. |
Output
The node outputs an array of JSON objects, one per input item, each containing:
success: A boolean indicating whether the cleanup operation succeeded (true) or failed (false).error: If the operation failed, this contains an error message string explaining the reason; otherwise, it isnull.
Example output:
[
{
"success": true,
"error": null
},
{
"success": false,
"error": "The prefix must have at least 4 characters, including an underscore (_)"
}
]
Dependencies
- Requires access to the local filesystem where the specified directory resides.
- No external API keys or services are needed.
- The node uses Node.js built-in
fsmodule with promises to read directories, check file stats, and delete files.
Troubleshooting
Common issues:
- Invalid prefix: The prefix must be at least 4 characters long and include an underscore. Otherwise, the node will not perform any deletions and will return an error.
- Directory access errors: If the specified directory does not exist or the node lacks permissions to read or delete files there, an error will be returned.
Error messages:
"The prefix must have at least 4 characters, including an underscore (_)": Indicates the prefix parameter is invalid."Error: <system error message>": Indicates a problem accessing the directory or deleting files, such as permission denied or directory not found. Verify the directory path and permissions.