0.1.12 • Published 11 years ago

dirco v0.1.12

Weekly downloads
3
License
ISC
Repository
github
Last release
11 years ago

dirco

Node.js module for listing directories and files recursively. It's using ES 6 generators and co.

It comes also with the regenerator runtime so it can be used with ES 5 engines like node 0.10 or below.

Install

  npm install dirco

Usage

//ES6
var dirco = require('dirco');
//ES5: 
var dirco = require('dirco/es5');


dirco(path [, options] , callback);
//using ES5: 
var dirco = require('dirco/es5')
, util = require('util');

dirco('./node_modules', {depth:2}, function(err, result) {
    console.log(util.inspect((result), {showHidden: false, depth: null}));
});

Options

depth: number (-1)                    // level of search depth, -1 is infinity
flat: bool (false)                   // list items in one array without hierarchy
stats: bool|array|string (true)       // append fs.Stats object

Returns directories and files with name, path and fs.Stats info as a tree.

[{
    "name": "co",
    "path": "node_modules/co",
    "type": "directory",
    "stats": {
      //...
    },
    "children": [
      {
        "name": "index.js",
        "path": "node_modules/co/index.js",
        "type": "file",
        "stats": {
         //...
        }
      },
      {
        "name": "package.json",
        "path": "node_modules/co/package.json",
        "type": "file",
        "stats": {
          //...
        }
      },
      {
        "name": "Readme.md",
        "path": "node_modules/co/Readme.md",
        "type": "file",
        "stats": {
          //...
        }
      }
    ]
  }]

Examples

Get total size of the directory (using flat option)

//using ES5: 
var dirco = require('dirco/es5')

dirco('./', {flat:true},function(err, result) {
    var i, totalSize = 0;
    for(i=0; i<result.length; i++) {
        totalSize += result[i].stats.size;
    }
    console.log(Math.round((totalSize / 1024), 10) + ' KB') ; // 142 KB
});

Searching in directory and file names using the filter option

dirco(__dirname+'/../', {filters:[/^.+\.js$/i], flat:true, stats:false}, function(err, result) {
  console.log(result);
});
0.1.12

11 years ago

0.1.11

11 years ago

0.1.10

11 years ago

0.1.9

11 years ago

0.1.8

11 years ago

0.1.7

11 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago