simple readdirp with filter and sync/async version
Features
- just traverse the file path, not the content of file
- readdirpSync for sync usecase
Usage
readdirpSync(dir, [filter])
sync to read the dir. the result is an array, which contains the file path(no filter param) or the filter return
dir
: the start directory, which will not include in the resultfilter
: the filter functionfilter(filePath, stats)
.filePath
is the full path for the sub dir or file.stats
is the lstat return- the
return
value will be pushed at the result. if you returnfalse
, then this file will be ignored
readdirp(dir, filter, done)
async to read the dir.
filter
:filter(filePath, stats, [callback])
.callback
:callback(err, ret)
. if no callback, then thereturn
will be used in the result. otherwise, callback'sret
parameter will be used in the result. if theret
param's value is false, the file will be ignored
done
: when finished, done is called.done(err, results)
var readdirp = readdirp;var readdirpSync = readdirpSync; //read current directory's sub file path(absolute path)var files = ; //read current directory's sub file relative pathvar files = ; //ignore all directory, only its filesvar files = ; //async with no-callback filter: filter is sync; //async with callback filter: filter is async;
License :
Licensed under MIT
Copyright (c) 2015 kiliwalk