@hyperse/delete-empty-folders
v1.0.1
Published
Recursively delete all empty folders in a directory and child directories.
Downloads
141
Readme
@hyperse/delete-empty-folders
Recursively delete all empty folders in a directory and child directories.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
(TOC generated by verb using markdown-toc)
Install
Install with npm:
$ npm install --save @hyperse/delete-empty-folders
Usage
import { deleteEmpty, deleteEmptySync } from '@hyperse/delete-empty-folders';
API
Given the following directory structure, the highlighted directories would be deleted.
foo/
└─┬ a/
- ├── aa/
├── bb/
│ └─┬ bbb/
│ │ ├── one.txt
│ │ └── two.txt
- ├── cc/
- ├ b/
- └ c/
async-await (promise)
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);
sync
Returns the array of deleted directories.
console.log(deleteEmptySync('foo/')); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']