Skip to content

Instantly share code, notes, and snippets.

@AKIo0O
Created May 14, 2015 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AKIo0O/3e1b4161412365d569fc to your computer and use it in GitHub Desktop.
Save AKIo0O/3e1b4161412365d569fc to your computer and use it in GitHub Desktop.
读取目录树
var fs = require('fs');
function readdir(path){
return fs.readdirSync(path);
}
function isDirectory(path){
return fs.lstatSync(path).isDirectory();
}
function process(path, space, line){
readdir(path).forEach(function(dir){
console.log( new Array(space).join(" ")+ "|" +new Array(line).join("--")+dir);
if(isDirectory(path + dir)){
process(path + dir + "/",space+2, 2);
}
});
}
process(__dirname+"/",1,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment