Socket
Socket
Sign inDemoInstall

walker

Package Overview
Dependencies
0
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    walker

A simple directory tree walker.


Version published
Weekly downloads
21M
decreased by-0.94%
Maintainers
0
Install size
6.55 kB
Created
Weekly downloads
 

Package description

What is walker?

The `walker` npm package is a tool designed for efficiently walking (traversing) file trees in a Node.js environment. It allows developers to easily perform operations on file systems, such as listing all files in a directory and its subdirectories, filtering files based on certain criteria, and processing each file individually. This package is particularly useful for tasks that involve bulk file operations, such as building a search index, file analysis, or automated file organization.

What are walker's main functionalities?

File Traversal

This feature allows the user to traverse all files starting from a specified directory. It emits events for each file found, enabling the execution of custom logic such as logging or processing of each file.

const walker = require('walker');
const path = '/path/to/start/directory';

walker(path)
  .on('file', function(file, stat) {
    console.log('Found file: ' + file);
  })
  .on('error', function(err, entry) {
    console.error('Error at: ' + entry + ' - ' + err);
  })
  .on('end', function() {
    console.log('All files have been processed');
  });

Directory Filtering

This feature demonstrates how to filter directories during traversal, allowing the user to skip certain directories (e.g., 'node_modules'). This is useful for focusing on relevant files and improving performance by avoiding unnecessary directories.

const walker = require('walker');
const path = '/path/to/start/directory';

walker(path)
  .filterDir(function(dir, stat) {
    // Only traverse directories that are not named 'node_modules'
    return dir.indexOf('node_modules') === -1;
  })
  .on('file', function(file, stat) {
    console.log('Found file: ' + file);
  });

Other packages similar to walker

Readme

Source

walker

A simple nodejs directory walker. It's not very featureful; this demonstrates the entire API:

Walker('/etc/')
  .filterDir(function(dir) {
    if (dir === '/etc/pam.d') {
      console.warn('Skipping /etc/pam.d and children')
      return false
    }
    return true
  })
  .on('dir', function(dir) {
    console.log('Got directory: ' + dir)
  })
  .on('file', function(file) {
    console.log('Got file: ' + file)
  })
  .on('error', function(er, target, stat) {
    console.log('Got error ' + er + ' on target ' + target)
  })
  .on('end', function(file) {
    console.log('Walker is done.')
  })

You specify a root directory to walk and optionally specify a function to prune sub-directory trees via the filterDir function. The Walker exposes a number of events, broadcasting each directory, file, error and finally the event to signal the end of the process.

TODO

  • Better symlink support.

Keywords

FAQs

Last updated on 25 Feb 2011

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc