Like fs.promises.readdir()
but excludes autogenerated contents for example .DS_Store
and Thumbs.db
const {readdir} = require('fs').promises;
const readdirClean = require('readdir-clean');
(async () => {
await readdir('.');
/*=> [
'.DS_Store',
'.AppleDouble',
'.LSOverride',
'a.txt',
'b.txt',
'Thumbs.db'
] */
await readdirClean('.');
/*=> [
'a.txt',
'b.txt'
] */
})();
npm install readdir-clean
const readdirClean = require('readdir-clean');
path: string | Buffer | Uint8Array | URL
(directory path)
Return: Promise<string[]>
Similar to Node.js built-in fs.promises.readdir()
, but different in the following points:
encoding
option is not supported.- The paths are filtered with
require('junk').not
.
(async () => {
const paths = await readdirClean('path/to/dir');
paths.includes('.Spotlight-V100'); //=> false
paths.includes('.Trashes'); //=> false
paths.includes('Desktop.ini'); //=> false
})();
ISC License © 2017 - 2019 Shinnosuke Watanabe