Created
May 14, 2015 07:50
-
-
Save AKIo0O/3e1b4161412365d569fc to your computer and use it in GitHub Desktop.
读取目录树
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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