node-walkdir
v1.0.0
Published
node walkdir
Downloads
678
Readme
node-walkdir
node traversal files (async/sync)
Requirements
node8 or higher
How to use it
Installation
$ yarn add node-walkdir
# or
$ npm install node-walkdir
Examples
const walkdir = require('node-walkdir')
/** async */
(async() => {
// walk all files by default
const allFiles = await walk('you-path');
console.log('files:', allFiles);
// only traverse the JS files
const jsFiles = await walk('you-path', '.js');
console.log('files:', jsFiles);
// traverse the JS and JSON files
const jsonFiles = await walk('you-path', ['.js', '.json']);
console.log('files:', jsonFiles);
// traverse the JS and JSON files by regexp
const json2Files = await walk('you-path', /\.js(on)?$/);
console.log('files:', json2Files);
// only traverse the JS files with 2 level directories deep.
const js2Files = await walk('you-path', '.js', 2);
console.log('files:', js2Files);
})();
/** sync */
// walk all files by default
const allFiles = walk.sync('you-path');
console.log('files:', allFiles);
// only traverse the JS files
const jsFiles = walk.sync('you-path', '.js');
console.log('files:', jsFiles);
// traverse the JS and JSON files
const jsonFiles = walk.sync('you-path', ['.js', '.json']);
console.log('files:', jsonFiles);
// traverse the JS and JSON files by regexp
const json2Files = walk.sync('you-path', /\.js(on)?$/);
console.log('files:', json2Files);
// only traverse the JS files with 2 level directories deep.
const js2Files = walk.sync('you-path', '.js', 2);
console.log('files:', js2Files);