node-dir
Advanced tools
Comparing version 0.1.6 to 0.1.8
{ | ||
"name": "node-dir", | ||
"version": "0.1.6", | ||
"version": "0.1.8", | ||
"description": "asynchronous file and directory operations for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index", |
@@ -95,2 +95,23 @@ [![Build Status](https://secure.travis-ci.org/fshost/node-dir.png)](http://travis-ci.org/fshost/node-dir) | ||
Note that for the files and subdirs the object returned is an array, and thus all of the standard array methods are available for use in your callback for operations like filters or sorting. Some quick examples: | ||
```javascript | ||
dir.files(__dirname, function(err, files) { | ||
if (err) throw err; | ||
// sort ascending | ||
files.sort(); | ||
// sort descending | ||
files.reverse(); | ||
// include only certain filenames | ||
files = files.filter(function (file) { | ||
return ['allowed', 'file', 'names'].indexOf(file) > -1; | ||
}); | ||
// exclude some filenames | ||
files = files.filter(function (file) { | ||
return ['exclude', 'these', 'files'].indexOf(file) === -1; | ||
}); | ||
}); | ||
``` | ||
Also note that if you need to work with the contents of the files asynchronously, please use the readFiles method. The files and subdirs methods are for getting a list of the files or subdirs in a directory as an array. | ||
@@ -107,3 +128,2 @@ #### subdirs( dir, callback ) | ||
#### paths(dir, [combine], callback ) | ||
@@ -110,0 +130,0 @@ Asynchronously iterate the subdirectories of a directory and its subdirectories and pass an array of both file and directory paths to a callback. |
16126
153