Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A set of utility functions for working with directories.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
README.md
index.js
package.json

README.md

node-dirutils

A set of utility functions for working with directories.

All functions are:

  • recursive - they include all subdirectories
  • sync - they use sync versions of FileSystem functions

Install

npm install node-dirutils

Functions

getFiles(dirPath[, exclude])

Get all files from the given directory. Optionaly filter the results with a exclude pattern/function.

  • dirPath {String} - Path to the dir
  • exclude {RegExp | Function(file)} - exclude pattern (RegExp) or a exclude function which should return true (exclude file) or false (do not exclude file)

Returns an array of files or an Error object.

var dirUtils = require("node-dirutils");

var all       = dirUtils.getFiles("/path/to/dir");
var withoutJs = dirUtils.getFiles("/path/to/dir", /^.*\.js$/);
var noHomers  = dirUtils.getFiles("/path/to/dir", function(file) {
    return file.indexOf("homer") >= 0;
});

getDirs(dirPath[, exclude])

Get all subdirectories from the given directory. Optionaly filter the results with a exclude pattern/function.

  • dirPath {String} - Path to the dir
  • exclude {RegExp | Function(dir)} - exclude pattern (RegExp) or a exclude function which should return true (exclude dir) or false (do not exclude dir)

Returns an array of directories or an Error object.

emptyDir(dirPath)

Remove the contents of the given directory.

  • dirPath {String} - Path to the dir

Returns true or an Error object.

removeDir(dirPath)

Remove the given directory and its contents.

  • dirPath {String} - Path to the dir

Returns true or an Error object.

Something went wrong with that request. Please try again.