Package Exports
- empty-dir
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (empty-dir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
empty-dir 
Check if a directory is empty.
Install
Install with npm:
$ npm install --save empty-dir
Usage
var emptyDir = require('empty-dir');
emptyDir('./', function (err, result) {
if (err) {
console.error(err);
} else {
console.log('Directory is empty:', result);
}
});
var result = emptyDir.sync('./test/empty');
console.log('Directory is empty:', result);
Filter function
Both async and sync take a filter function as the second argument, to ignore files like .DS_Store
on mac or Thumbs.db
on windows from causing false-negatives.
var emptyDir = require('empty-dir');
function filter(filepath) {
return !/(Thumbs\.db|\.DS_Store)$/i.test(filepath);
}
emptyDir('./', filter, function (err, isEmpty) {
if (err) {
console.error(err);
} else {
console.log('Directory is empty:', isEmpty);
}
});
var isEmpty = emptyDir.sync('./test/empty', filter);
console.log('Directory is empty:', isEmpty);
Release History
- 2018-03-09 - v1.0.0 - refactored "isEmpty" logic so that it returns early, as soon as a non-filtered file is encountered, instead of filtering the entire list and comparing against length. Also allows an array to be passed (this avoids having to call
fs.readdir()
multiple times). - 2016-02-07 - v0.2.0 - add filter support
- 2014-05-08 - v0.1.0 - initial release