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 = ; var all = dirUtils;var withoutJs = dirUtils;var noHomers = dirUtils;
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.