$ cnpm install read-file-tree
recursively read contents of all files in a directory
npm install read-file-tree
var readFileTree = require('read-file-tree')
readFileTree('/path/to/directory', function (err, tree) {
console.log(tree)
})
readFileTree(basedir[, opts], cb)
Recursively read contents of all files in the directory basedir
. opts
can be an object:
opts.encoding
- encoding to pass to fs.readFile()
, by default a Buffer is returnedcb
is a node-style callback receiving an error
in the first parameter, and a tree
object in the second. Object keys in the tree
object are file names, while values are the file contents. Nested directories have another tree
object as their value. For example, the test/fixture directory results in this object:
{ 'one.js': '1;\n',
'two.js': '2;\n',
a: {
b: {
'c.txt': 'this is c\n',
c: {
'd.txt': 'file d\n' } } } }
readFileTree.sync(basedir[, opts])
The same, but sync. Returns tree
.
flat(readFileTree('./dest'), { delimiter: '/' })
// { 'a.txt': '',
// 'some/dir/name/b.txt': '' }
Copyright 2014 - 2017 © taobao.org |