const deleteEmpty = require('{%= name %}');
Given the following directory structure, the highlighted directories would be deleted.
foo/
└─┬ a/
- ├── aa/
├── bb/
│ └─┬ bbb/
│ │ ├── one.txt
│ │ └── two.txt
- ├── cc/
- ├ b/
- └ c/
If no callback is passed, a promise is returned. Returns the array of deleted directories.
(async () => {
let deleted = await deleteEmpty('foo');
console.log(deleted); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
})();
// or
deleteEmpty('foo/')
.then(deleted => console.log(deleted)) //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
.catch(console.error);
Returns the array of deleted directories in the callback.
deleteEmpty('foo/', (err, deleted) => {
console.log(deleted); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
});
Returns the array of deleted directories.
console.log(deleteEmpty.sync('foo/')); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
To use the delete-empty
command from any directory you must first install the package globally with the following command:
$ npm install --global delete-empty
Usage
Usage: $ delete-empty <directory> [options]
Directory: (optional) Initial directory to begin the search for empty
directories. Otherwise, cwd is used.
[Options]:
-c, --cwd Set the current working directory for folders to search.
-d, --dryRun Do a dry run without deleting any files.
-h, --help Display this help menu
-V, --version Display the current version of rename
-v, --verbose Display all verbose logging messages (currently not used)