4.1.0-next.1573684207.8b98b43458ac5173b6fceae8e93f32c3bfc5a804 • Published 6 years ago

scandirectory v4.1.0-next.1573684207.8b98b43458ac5173b6fceae8e93f32c3bfc5a804

Weekly downloads
75,640
License
MIT
Repository
github
Last release
6 years ago

Scan a directory recursively with a lot of control and power

npm

Usage

var scandir = require('scandirectory')
var path = process.cwd()
var options = {}
function completionCallback (err, list, tree) {
	console.log({
		error: err,
		list: list,
		tree: tree
	})
	/*
	{
		error: null,
		list: {
			'a file.txt': 'file',
			'a directory': 'dir',
			'a directory/a sub file.txt': 'file'
		},
		tree: {
			'a file.txt': true,
			'a directory': {
				'a sub file.txt': 'true
			}
		}
	}
	*/
}
scandir(path, options, completionCallback)

Scan directory options:

  • action - (default null) can be null or a function to use for both the fileAction and dirAction
  • fileAction - (default null) can be null, false, or a function to be the action callback
  • dirAction - (default null) can be null, false, or a function to the action callback
  • recurse - (default true) can be null or a boolean for whether or not to scan subdirectories too
  • readFiles - (default false) can be null or a boolean for whether or not we should read the file contents

The options object is also sent to ignorefs so you can use its options too

The completion callback accepts the following arguments:

  • err - null or an error that has occured
  • list - a collection of all the child nodes in a list/object format: - {fileRelativePath: 'dir|file'}
  • tree - a collection of all the child nodes in a tree format: - {dir: {dir:{}, file1:true} } - if the readFiles option is true, then files will be returned with their contents instead

The results for a specific argument is only generated if the argument is requested.

The action callbacks accept the following arguments:

  • fullPath - the full/absolute path of the current file/directory
  • relativePath - the relative path of the current file/directory with respect to the original scanning path
  • filename - the basename of the current file/directory
  • stat - a simple stat object provided by readdir-cluster

The action callbacks can return false to skip the path from being processed further.

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Discover the release history by heading on over to the HISTORY.md file.

These amazing people are maintaining this project:

No sponsors yet! Will you be the first?

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Unless stated otherwise all works are:

and licensed under:

7.3.0

2 years ago

8.1.0

2 years ago

8.1.1

2 years ago

8.0.0

2 years ago

6.17.0

2 years ago

7.1.0

2 years ago

7.0.0

2 years ago

6.18.0

2 years ago

7.2.0

2 years ago

6.16.0

5 years ago

6.15.0

5 years ago

6.14.0

5 years ago

6.13.0

5 years ago

6.12.0

6 years ago

6.11.0

6 years ago

6.10.0

6 years ago

6.8.0

6 years ago

6.7.0

6 years ago

6.6.0

6 years ago

6.5.0

6 years ago

6.4.0

6 years ago

6.3.0

6 years ago

6.2.0

6 years ago

6.1.0

6 years ago

6.0.0

6 years ago

5.3.0

6 years ago

5.2.0

6 years ago

5.1.0

6 years ago

5.0.0

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.5.0

11 years ago