read-file-tree
recursively read contents of all files in a directory
Last updated a year ago by goto-bus-stop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install read-file-tree 
SYNC missed versions from official npm registry.

read-file-tree

recursively read contents of all files in a directory

npm travis standard

Install

npm install read-file-tree

Usage

var readFileTree = require('read-file-tree')

readFileTree('/path/to/directory', function (err, tree) {
  console.log(tree)
})

API

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 returned

cb 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.

See Also

  • write-file-tree - write an object to nested file tree, with one file for each value
  • flat - flatten and unflatten objects—you can use this to create an object with relative paths as keys:
    flat(readFileTree('./dest'), { delimiter: '/' })
    // { 'a.txt': '',
    //   'some/dir/name/b.txt': '' }
    

License

MIT

Current Tags

  • 1.1.2                                ...           latest (a year ago)

4 Versions

  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 5
Dependencies (0)
None
Dev Dependencies (3)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |