Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Asynchronous directory and subdir file listing for node.js v6+

Notifications You must be signed in to change notification settings

t3hmun/t3hmun-walk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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);
});

About

Asynchronous directory and subdir file listing for node.js v6+

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published