I am using boto and python and amazon s3.
If i use
[key.name for key in list(self.bucket.list())]
then i get all the keys of all the files.
mybucket/files/pdf/abc.pdf
mybucket/files/pdf/abc2.pdf
mybucket/files/pdf/abc3.pdf
mybucket/files/pdf/abc4.pdf
mybucket/files/pdf/new/
mybucket/files/pdf/new/abc.pdf
mybucket/files/pdf/2011/
what is the best way to
1. either get all folders from s3
2. or from that list just remove the file from the last and get the unique keys of folders
I am thinking of doing like this
set([re.sub("/[^/]*$","/",path) for path in mylist]
building on sethwm's answer:
To get the top level directories:
list(bucket.list("", "/"))
To get the subdirectories of files
:
list(bucket.list("files/", "/")
and so on.