$ gnpm install find
Find files or directories by name.
$ npm install --save find
Find all files in current directory.
var find = require('find');
find.file(__dirname, function(files) {
console.log(files.length);
})
Filter by regular expression.
find.file(/\.js$/, __dirname, function(files) {
console.log(files.length);
})
.use()
methodpattern
option is now optionalfind.file(__dirname, function(files) {
//
})
find.dir(__dirname, function(dirs) {
//
})
find.eachfile(__dirname, function(file) {
//
})
find.eachdir(__dirname, function(dir) {
//
})
var files = find.fileSync(__dirname);
var dirs = find.dirSync(__dirname);
Handling errors in asynchronous interfaces
find
.file(__dirname, function(file) {
//
})
.error(function(err) {
if (err) {
//
}
})
Detect end
in find.eachfile
and find.eachdir
find
.eachfile(__dirname, function(file) {
//
})
.end(function() {
console.log('find end');
})
fs
: The internal fs object to be used.const { fs, vol } = require('memfs');
const json = {
'./README.md': '1',
'./src/index.js': '2'
};
vol.fromJSON(json, '/app');
find
.use({ fs: fs })
.file('/app', console.log);
Copyright 2013 - present © cnpmjs.org | Home |