node-dirutils

A set of utility functions for working with directories.

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
npm install node-dirutils

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;
});

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.

Remove the contents of the given directory.

  • dirPath {String} - Path to the dir

Returns true or an Error object.

Remove the given directory and its contents.

  • dirPath {String} - Path to the dir

Returns true or an Error object.