Skip to content

52cik/node-walkdir

Repository files navigation

node-walkdir

node traversal files (async/sync)

Linux Build Coverage Status Dependencies node license MIT

中文文档

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);

About

node traversal files (async/sync)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published