Skip to content

Recursively delete all empty folders in a directory and child directories.

License

Notifications You must be signed in to change notification settings

hyperse-io/delete-empty-folders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@hyperse/delete-empty-folders

build stable version GitHub top language Licence

Recursively delete all empty folders in a directory and child directories.

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/']