Created
March 13, 2014 13:54
-
-
Save llad/9528923 to your computer and use it in GitHub Desktop.
Create a CSV of the contents of a directory. #nodejs
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 fs = require('fs'), | |
dir = process.argv[2] || ".", | |
filenames, | |
i, | |
csv; | |
filenames = fs.readdirSync(dir); | |
for (i = 0; i < filenames.length; i++) { | |
console.log(filenames[i]); | |
} | |
csv = filenames.join('\n'); | |
fs.writeFile('contents.csv', csv, function (err) { | |
if (err) throw err; | |
console.log('It\'s saved!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment