Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dirTree (filename, cb) {
- fs.lstat(filename, function (err, stat) {
- if (err) {
- return cb(err);
- }
- var info = {
- "path": filename,
- "name": path.basename(filename)
- };
- if (stat.isDirectory()) {
- info.type = "folder";
- fs.readdir(filename, function (err, children) {
- if (err) {
- return cb(err);
- }
- info.children = [];
- var browsed = 0;
- children.forEach(function (child, index) {
- dirTree(path.join(filename, child), function (err, childInfo) {
- if (err) {
- return cb(err);
- }
- info.children[index] = childInfo;
- if (++browsed === children.length) {
- cb(null, info);
- }
- });
- });
- });
- } else {
- info.type = "file";
- cb(null, info);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement