Safely wipe a folder.
This is the perfect library for when you want to wipe a folder with user's confirmation.
- If the folder is empty (or contains only useless files like
Thumbs.dbas configured with
config.ignore), the folder will be removed without asking anything.
config.forceis set to
true, wipe anyway.
- If the session is not interactive, raise an exception.
- Prompt the user for confirmation, and raise an exception if the answer is negative.
You can configure the following variables:
||Streams to use for I/O.||
||An array of files to ignore when checking if a directory is empty.||
||A (supposed) parent directory of the directory to wipe. If the parent is contained in the directory to wipe, the process will be aborted in all cases.|
||Whether the session is interactive.||
||Whether to force the wipe if the folder is not empty.||
||The error messages are not printed if this is set to
||An object of messages for user prompt and error display.|
The messages are:
||Error message when the folder to wipe is contained in the configured parent folder.|
||Text to prompt the user to confirm the (not empty) directory wipe.|
||Error message when the user refuses to wipe the folder.|
The function is asynchronous and return a promise. Nothing is passed to
the success function, but you'll get an
Error instance in the error
function. It can have the following
||Refused to remove the directory since it's containing the supposed parent.|
||The user aborted the operation (or we're not in an interactive session and
var safeWipe = ;;
Bind a config object
var mySafeWipe =;;;