node-dirutils

0.0.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i node-dirutils

Weekly Downloads

1

Version

0.0.1

License

BSD

Last publish

Collaborators

  • centi