Skip to content

Instantly share code, notes, and snippets.

@llad
Created March 13, 2014 13:54
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 llad/9528923 to your computer and use it in GitHub Desktop.
Save llad/9528923 to your computer and use it in GitHub Desktop.
Create a CSV of the contents of a directory. #nodejs
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