https://github.com/t3hmun/t3hmun-walk
Asynchronous directory and subdir file listing for node.js v6+
https://github.com/t3hmun/t3hmun-walk
directory subdir walk
Last synced: 12 months ago
JSON representation
Asynchronous directory and subdir file listing for node.js v6+
- Host: GitHub
- URL: https://github.com/t3hmun/t3hmun-walk
- Owner: t3hmun
- Created: 2016-09-10T11:47:32.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-22T16:20:57.000Z (over 9 years ago)
- Last Synced: 2025-06-01T16:45:21.440Z (about 1 year ago)
- Topics: directory, subdir, walk
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# t3hmun-walk
## What
Some functions that asynchronously list all the files in a directory and all of it sub-directories recursively.
Makes use of features of ES6; intended for use with Node.js v6+.
## Why
The existing packages looked either wrong or odd, also this seems like nice learning exercise (learning JS, Node.js, ES6).
## Usage
### All Files and Sub-Directories
```js
const walk = require('walk');
walk.all('./aFolder', function(err, files){
// err will be an Error from fs.readdir() or fs.stat().
if(err) throw err;
// Will output a list of files, paths joined to the original dir specified.
console.log(files);
})
```
### Filtered
```js
const walk = require('walk');
const path = require('path');
// Function that only returns true for .md files.
function onlyMdFiles(filePath){
return filePath.endsWith('.md');
}
// Functions that returns true for everything except .git directory.
function excludeGit(dirPath){
// dirPath may be the entire path or a relative path to the directory.
// Use path to extract the dir name only.
let dirname = path.basename(dirName);
return dirname != '.git';
}
walk.where('./', onlyMdFiles, excludeGit, function(err, list){
if(err) throw err;
console.log(files);
});
```