https://github.com/hyperse-io/delete-empty-folders
Recursively delete all empty folders in a directory and child directories.
https://github.com/hyperse-io/delete-empty-folders
del delete delete-empty-folders empty hyperse
Last synced: about 2 months ago
JSON representation
Recursively delete all empty folders in a directory and child directories.
- Host: GitHub
- URL: https://github.com/hyperse-io/delete-empty-folders
- Owner: hyperse-io
- License: mit
- Created: 2024-06-12T03:38:43.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-06-12T07:52:00.000Z (12 months ago)
- Last Synced: 2025-03-07T07:23:19.932Z (3 months ago)
- Topics: del, delete, delete-empty-folders, empty, hyperse
- Language: TypeScript
- Homepage:
- Size: 1.04 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @hyperse/delete-empty-folders
> Recursively delete all empty folders in a directory and child directories.
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [async-await (promise)](#async-await-promise)
- [async callback](#async-callback)
- [sync](#sync)
- [examples](#examples)## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save @hyperse/delete-empty-folders
```## Usage
```ts
import { deleteEmpty, deleteEmptySync } from '@hyperse/delete-empty-folders';
```## API
Given the following directory structure, the **highlighted directories** would be deleted.
```diff
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.
```ts
(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.
```js
console.log(deleteEmptySync('foo/')); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
```