Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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