Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scandirectory

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scandirectory

Scan a directory recursively with a lot of control and power

  • 7.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
decreased by-9.27%
Maintainers
1
Weekly downloads
 
Created
Source

scandirectory

Status of the GitHub Workflow: bevry NPM version NPM downloads
GitHub Sponsors donate button ThanksDev donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Scan a directory recursively with a lot of control and power

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.

Contribute

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

Install

npm

  • Install: npm install --save scandirectory
  • Import: import * as pkg from ('scandirectory')
  • Require: const pkg = require('scandirectory')

Editions

This package is published with the following editions:

  • scandirectory aliases scandirectory/index.cjs which uses the Editions Autoloader to automatically select the correct edition for the consumer's environment
  • scandirectory/source/index.js is ESNext source code for Node.js 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules
  • scandirectory/edition-node-21/index.js is ESNext compiled for Node.js 21 with Require for modules
  • scandirectory/edition-node-4/index.js is ESNext compiled for Node.js 4 with Require for modules

History

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

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

GitHub Sponsors donate button ThanksDev donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

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

License

Unless stated otherwise all works are:

and licensed under:

Keywords

FAQs

Package last updated on 14 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc