Boto3 S3: Get files without getting folders

后端 未结 4 808
别那么骄傲
别那么骄傲 2020-12-15 12:54

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/         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 13:48

    One way to filter out folders is by checking the end character of the Object if you are certain that no files end in a forward slash:

    for object_summary in objects.all():
        if object_summary.key[-1] == "/":
            continue
    

提交回复
热议问题