Do the traversal of the source directory structure
$ npm install dir-ls --savewith options mode:
let ls = require('dir-ls')
ls('./someDir', {
readMode: 'utf8',
justFind: /png|jpg|gif/,
dirCallback(res) {
//do something here
},
fileCallback(res) {
//do something here
},
errorHandle(err) {
//handle error
},
allDone(){
//dir-ls have been finished
}
})without options mode:
let ls = require('dir-ls')
ls('./someDir', function(res){
//equal to fileCallBack
})There is only one function in dir-ls.
@param
- path <string>
Do the traversal of the source directory structure, thepathis the target directory that you want to traverse it. - options <object>|<Function>
Theoptionscould be an object which configures the methods detailedly.
If no readMode is specified, then the raw buffer is returned.
This options will filter file name and return the files that you want.
This options will filter other file formats and return the files that you want. Notic: if you want to match more than one file format such as json and js, you need to write the RegExp like /json$|js$/ to make sure the dir-ls use the whole word to match the file
This function will be called after an directory have been traversed.
This function will be called after a file have been traversed.
This function will be called after the whole directory have been traversed.
This function will be called when any error were thrown.
The options could be a function which perform as options.fileCallback.
$ npm test