Last active
July 26, 2017 08:56
-
-
Save sudikrt/fa17d0c7896e81930bff8510436edcc8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function filewalker(dir, done) { | |
let results = []; | |
fs.readdir(dir, function (err, list) { | |
if (err) return done(err); | |
var pending = list.length; | |
if (!pending) return done(null, results); | |
list.forEach(function (file) { | |
file = path.resolve(dir, file); | |
fs.stat(file, function (err, stat) { | |
// If directory, execute a recursive call | |
if (stat && stat.isDirectory()) { | |
// Add directory to array [comment if you need to remove the directories from the array] | |
//results.push(file); | |
filewalker(file, function (err, res) { | |
//path.relative(__dirname + "/uploads", res) | |
results = results.concat(res); | |
if (!--pending) done(null, results); | |
}); | |
} else { | |
results.push(file); | |
if (!--pending) done(null, results); | |
} | |
}); | |
}); | |
}); | |
}; |
This file contains hidden or 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 getFileData = function (dir) { | |
var result = []; | |
fs.readdirSync(dir).forEach(function (file) { | |
var stat = fs.statSync(dir + "/" + file); | |
if (stat && stat.isFile()) { | |
result.push(file); | |
} | |
}); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment