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

walkdir

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

walkdir

Find files simply. Walks a directory tree emitting events based on what it finds. Presents a familiar callback/emitter/a+sync interface. Walk a tree of any depth.

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is walkdir?

The walkdir npm package is a utility for recursively traversing directories and handling files and directories found within. It provides a simple and efficient way to walk through directory trees, making it useful for tasks such as file system analysis, batch processing of files, and more.

What are walkdir's main functionalities?

Basic Directory Traversal

This feature allows you to traverse a directory and log each file and directory found. The callback function receives the path and stat object for each item.

const walk = require('walkdir');

walk('/path/to/directory', function(path, stat) {
  console.log('Found:', path);
});

Filtering Files

This feature demonstrates how to filter files based on certain criteria, such as file extension. In this example, only JavaScript files are logged.

const walk = require('walkdir');

walk('/path/to/directory', function(path, stat) {
  if (stat.isFile() && path.endsWith('.js')) {
    console.log('Found JavaScript file:', path);
  }
});

Handling Errors

This feature shows how to handle errors that may occur during directory traversal. The 'error' event is emitted with the path and error details.

const walk = require('walkdir');

const emitter = walk('/path/to/directory');

emitter.on('file', function(path, stat) {
  console.log('Found file:', path);
});

emitter.on('error', function(path, err) {
  console.error('Error for path', path, ':', err);
});

Asynchronous Traversal

This feature demonstrates synchronous directory traversal, where the entire directory tree is read and returned as an array of paths.

const walk = require('walkdir');

const paths = walk.sync('/path/to/directory');

paths.forEach(function(path) {
  console.log('Found:', path);
});

Other packages similar to walkdir

Keywords

FAQs

Package last updated on 07 Feb 2019

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