Skip to content

stefanpenner/node-walk-sync

 
 

Repository files navigation

node-walk-sync

Build Status

Return an array containing all recursive files and directories under a given directory, similar to Unix find. Follows symlinks. Bare-bones, but very fast.

Similar to wrench.readdirSyncRecursive, but adds trailing slashes to directories.

Not to be confused with node-walk, which has both an asynchronous and a synchronous API.

Installation

npm install --save walk-sync

Usage

var walkSync = require('walk-sync');
var paths = walkSync('foo')

Given foo/one.txt and foo/subdir/two.txt, paths will be the following array:

['one.txt', 'subdir/', 'subdir/two.txt']

Note that directories come before their contents, and have a trailing slash.

Symlinks are followed.

Globs

Similarly to node-glob, walkSync can use globs to further refine the output. The difference is walkSync accepts are array of globs:

var walkSync = require('walk-sync', ['**/*.js']);

Given foo/one.js and foo/two.txt, bar.jss will be the following array:

['bar.js', 'foo/two.js']

Background

walkSync(baseDir) is a faster substitute for

glob.sync('**', {
  cwd: baseDir,
  dot: true,
  mark: true,
  strict: true
})

About

List directory contents recursively

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%