Created
February 4, 2016 10:13
Returns an array of subfolders for a given path on S3, with aws-sdk (ruby)
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
# Returns an array of subfolders for a given path | |
def folders(path = '/') | |
objs = [] | |
next_marker = nil | |
loop do | |
response = Aws::S3::Client.new.list_objects( | |
bucket: 'bucket', | |
delimiter: "/", | |
encoding_type: "url", | |
marker: next_marker, | |
prefix: File.join(path, "") # we need trailing slash | |
) | |
next_marker = response.next_marker | |
objs += response.common_prefixes.map { |cp| File.basename(cp.prefix) } | |
break unless response.is_truncated | |
end | |
objs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment