Amazon s3 从bucket.objects.filter中排除S3文件夹(前缀=前缀)
我有一个python boto3代码,它列出了s3文件夹/前缀下的所有对象。此代码将返回所有对象,即 温度/测试/日期=2019年9月17日/ 温度/测试/日期=17-09-2019/100.json 我想从响应中排除temp/test/date=17-09-2019/键。我知道s3中不存在文件夹的概念。请在下面找到我的代码:Amazon s3 从bucket.objects.filter中排除S3文件夹(前缀=前缀),amazon-s3,boto3,Amazon S3,Boto3,我有一个python boto3代码,它列出了s3文件夹/前缀下的所有对象。此代码将返回所有对象,即 温度/测试/日期=2019年9月17日/ 温度/测试/日期=17-09-2019/100.json 我想从响应中排除temp/test/date=17-09-2019/键。我知道s3中不存在文件夹的概念。请在下面找到我的代码: bucket_name = 'temp-bucket' prefix = 'temp/test/date=17-09-2019' bucket = s3_resourc
bucket_name = 'temp-bucket'
prefix = 'temp/test/date=17-09-2019'
bucket = s3_resource.Bucket(bucket_name)
s3_files = list(bucket.objects.filter(Prefix=prefix))
for file in s3_files:
print(file)
有没有办法从响应中排除文件夹
谢谢没有办法过滤出结果,但您可以按如下方式进行操作:
import boto3
bucket_name = 'temp-bucket'
s3 = boto3.resource('s3')
ignore = s3.Bucket(bucket_name ).objects.filter(Prefix='temp/test/date=17-09-2019')
response = s3.Bucket(bucket_name ).objects.all()
for item in response:
if item not in ignore:
print(item.key)