I play with the boto library to access the amazon s3 bucket. I am trying to list all the files and folders in a given folder in a bucket. I use this to get all files and folders:
for key in bucket.list(): print key.name
This gives me all the files and folders in the root, as well as subfolders in which there are files inside them, for example:
root/ file1 file2 folder1/file3 folder1/file4 folder1/folder2/file5 folder1/folder2/file6
How can I only list the contents of say folder1 , where it will say something like:
files: file3 file4 folders: folder2
I can navigate to the folder using
for key in in bucket.list(prefix=path/to/folder/)
but in this case, it lists the files in folder2 as the files of folder1 , because I'm trying to use string manipulations in the path to the bucket. I tried every script and it still breaks if there are longer paths and when folders have several files and folders (and there are more files in these folders). Is there a recursive way to solve this problem?
source share