scandir-async

0.1.15 • Public • Published

scandir-async Built with Grunt

MIT License NPM version NPM downloads Build Coverage

  • Iterates trough a directory and returns a js object tree
  • Result can be directories/files sorted first

Install

npm install scandir-async

Usage

var scandir = require('scandir-async'),
    exec = require('scandir-async').exec;
scandir.exec([folder], [options]).then(function(data){
    // Q.promise resolved
}, function(err){
    // Q.promise rejected
});
// or exposed
exec([folder], [options]).then(function(data){
    // Q.promise resolved
}, function(err){
    // Q.promise rejected
});

Tree Object

{
    isdir: true,
    name: dirname,
    fullpath: /abs/path/to/dirname,
    stats: {
        dev: 310691535,
         ino: 2814749767439347,
         uid: 0,
         gid: 0,
         rdev: 0,
         size: 0,
         mode: 16822,
         nlink: 1,
         blocks: false,
         blksize: false,
         atime: 1436683130000,
         mtime: 1436683130000,
         ctime: 1436683130000,
         birthtime: 1436683129000
    },
    files: [{
            isdir: false,
            files: false,
            name: dirname,
            stats: [object],
            fullpath: /abs/path/to/dirname
        }, {
            isdir: true,
            files: [...],
            name: dirname,
            stats: [object],
            fullpath: /abs/path/to/dirname
        },
        {...}
    ]
}

Options

Folder

  • absolute path

Options Object

Currently implemented

{
    sorted: false, // Default not sorted
    sorted: true, // 'ASC'
    sorted: 'ASC',
    sorted: 'DESC',
}

Not implemented yet

{
    depth: 0,
    filters: ['**/*.hml']
}

Issues

Tests

Git add/clone does not take care of empty folder used for tests, it must be created manually Or launch test using npm test

mkdir spec/expected/explore_method/subnofiles
mkdir spec/expected/files_method/nofile
mkdir spec/expected/files_method/threefile/subfolder

History

  • v0.1.15: Sorted fix name lowercase
  • v0.1.12: Sorted options added
  • v0.1.11: Files prop for directory is an array
  • v0.1.10: Changes on tree object

Package Sidebar

Install

npm i scandir-async

Weekly Downloads

0

Version

0.1.15

License

MIT

Last publish

Collaborators

  • sixertoy