emptydir
You now get to delete files recursively while preserving the directories from Node.Js and your terminal.
installation
You require npm to install/download this module.
npm install emptydir
If you wish to install it globally on your machine:
npm install -g emptydir
The module emptydir
will be added in the correct node_modules directory and the command emptydir
will be added to your terminal.
usage
from Node.Js (programmatic)
var emptydir = ; /* * Assuming the variable 'my_path' holds a path to* a folder on your machine*/ /** errs will be an array with all the errors that occurred* Otherwise null on success*/emptydir; /** callback is called per file(and not directory) being worked on.* err is null on success*/emptydir; /** Synchronous. Returns an array of all the errors that occurred while* working on the files in the directory.* On success, returns an empty array. Thus it is safe to immediately* loop through the errors in the array.*/errs = emptydir;errs;
notes
By saying working on a file, we mean to try and remove it.
All of the methods:
- If the path passed is a file, it is simply deleted. It's 'not amust the path points to a directory.
- Symbolic links are not dereferenced. They are deleted equally as files.
Any of the Asynchronous methods:
- If a callback is not passed, the methods will complete as would have if callback was passed.
emptydir.emptyDir(path [, callback])
- Callback is called only once after the working on the files is complete.
- On error, a list of all errors occurred during the recursive removal is passed to the callback.
- On success, error will be
null
emptydir.emptyDirs(path [, callback])
- The callback is called each time a file is worked on.
- path of the file worked on is always passed as the second argument to the callback on both success and error.
emptydir.emptyDirsSync(path)
- The return value will always be an array. Thus no need to test for that.
Note: The idea of the methods is to keep going even when an error is encountered. This ensures we remove as much files as possible.
from your terminal (commandline)
# output help info about available options. $ emptydir -h$ emptydir --help...# show the version number of emptydir installed. $ emptydir --version...# empty directoryA $ emptydir directoryA...# empty directoryA and directoryB $ emptydir directoryA directoryB...# be verbose while emptying directoryA $ emptydir -v directoryA$ emptydir --verbose directoryA
notes
- If a regular file, instead of a directory, is passed to
emptydir
it will just be deleted, if possible. - Verbose option is unstable and may gave you false errors. That is,
emptydir
may remove some files but the commandline runner may report them back as failed.
version info
Aspect | Detail |
---|---|
version | 0.0.0 |
nodejs | 0.10.*, 0.8.* |
dependencies | none |
last updated | 28th July, 2014 |
contribution
Fork this repo, hack it and send a Pull Request. Please try and include a test as in the tests directory.
If you encounter a bug, even if you could fix it yourself (a pull request would be better in this case), please create an issue.
Also some geek talk is appreciated at @MUGO_GOCHO.
license
This source code is licensed under the MIT license.