Using boto3, how can I retrieve all files in my S3 bucket without retrieving the folders?
Consider the following file structure:
file_1.txt
folder_1/
There are no folders in S3. What you have is four files named:
file_1.txt
folder_1/file_2.txt
folder_1/file_3.txt
folder_1/folder_2/folder_3/file_4.txt
Those are the actual names of the objects in S3. If what you want is to end up with:
file_1.txt
file_2.txt
file_3.txt
file_4.txt
all sitting in the same directory on a local file system you would need to manipulate the name of the object to strip out just the file name. Something like this would work:
import os.path
full_name = 'folder_1/folder_2/folder_3/file_4.txt'
file_name = os.path.basename(full_name)
The variable file_name
would then contain 'file_4.txt'
.