list-empty-files

1.0.0 • Public • Published

list-empty-files

npm version Build Status Coverage Status

List all empty files in a given directory

const listEmptyFiles = require('list-empty-files');
 
/*
  a.txt: 'Hi'
  b.txt: ''
  c.txt: 'Hello'
  d.txt: ''
*/
 
listEmptyFiles('my-dir').then(files => {
  files;
  /* Set {
    '/Users/example/my-dir/b.txt',
    '/Users/example/my-dir/d.txt'
  } */
});

Installation

Use npm.

npm install list-empty-files

API

const listEmptyFiles = require('list-empty-files');

listEmptyFiles(dir)

dir: string (directory path)
options: Object (readdir-sorted options)
Return: Promise<Set<string>>

The promise will be fulfilled with a Set of strings — absolute paths of all zero byte files included in the given directory.

Options are directly passed to the underlying readdir-sorted to control the order of results.

listEmptyFiles('/empty-files').then(files => {
  const iterator = files.keys();
 
  iterator.next().value; //=> '/empty-files/10.js'
  iterator.next().value; //=> '/empty-files/2a.js'
  iterator.next().value; //=> '/empty-files/2A.js'
});
 
listEmptyFiles('/dir', {
  numeric: true,
  caseFirst: 'upper'
}).then(files => {
  const iterator = files.keys();
 
  iterator.next().value; //=> '/empty-files/2A.js'
  iterator.next().value; //=> '/empty-files/2a.js'
  iterator.next().value; //=> '/empty-files/10.js'
});

License

ISC License © 2018 Shinnosuke Watanabe

Package Sidebar

Install

npm i list-empty-files

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • shinnn