Created
June 5, 2018 17:44
-
-
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
This file contains 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 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