Determine if folder or file key - Boto

前端 未结 2 1300
悲&欢浪女
悲&欢浪女 2020-12-21 15:16

Using boto and Python I am trying to differentiate whether a key is returning a folder of file (I am aware that S3 treats both exactly the same as I am not dealing with a fi

2条回答
  •  隐瞒了意图╮
    2020-12-21 15:29

    S3.Object and S3.ObjectSummary will have the following property:

    'ContentType': 'application/x-directory'

    if the key is a directory.

    for s3_obj_summary in bucket.objects.all():
      if s3_obj_summary.get()['ContentType'] == 'application/x-directory':
        print(str(s3_obj_summary))
    

    https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.ObjectSummary.get

提交回复
热议问题