Skip to content

Instantly share code, notes, and snippets.

@scripting
Created June 5, 2018 17:44
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 scripting/a69f2dcd4f6c40d3418670c7611a1b73 to your computer and use it in GitHub Desktop.
Save scripting/a69f2dcd4f6c40d3418670c7611a1b73 to your computer and use it in GitHub Desktop.
JS code to ask AWS if an S3 path is a folder with files in it
function s3FolderExists (s3path, callback) {
var flHaveCalledBack = false;
var splitpath = s3.splitPath (s3path);
var pathToLookFor = splitpath.Key + "/";
s3.listObjects (s3path, function (obj) {
if (obj.flLastObject === undefined) {
if (utils.beginsWith (obj.Key, pathToLookFor)) {
if (!flHaveCalledBack) {
callback (true);
flHaveCalledBack = true;
}
}
}
else {
if (!flHaveCalledBack) {
callback (false);
flHaveCalledBack = true;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment