Skip to content

Instantly share code, notes, and snippets.

@steve-ross
Created February 3, 2020 16:53
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 steve-ross/a70e8a748c7ed6a8c426b9f7760580a9 to your computer and use it in GitHub Desktop.
Save steve-ross/a70e8a748c7ed6a8c426b9f7760580a9 to your computer and use it in GitHub Desktop.
read dir node script invoke: node readdir PATHTODIR
const path = require('path');
const fs = require('fs');
//joining path of directory
const directoryPath = path.join(process.argv[2]);
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
const arrayOfFiles = [];
const s3Path = 'https://gftc2020.s3.amazonaws.com/galleries/monday-03-20/';
files.forEach(function (file) {
// Do whatever you want to do with the file
arrayOfFiles.push(s3Path + file);
console.log('"' + s3Path + file + '"' + ',');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment