鉴于我有这样的东西:
"s3://folder1/folder2/folder3/folder4/folder4.5/folder4.6/folder5/folder6/folder7/file_name.csv"
我该如何解析它,以使我得到Bucket,然后得到Key,因为它减去文件名的last /?
我正在尝试获取路径,以便可以列出路径中的所有文件。
答案 0 :(得分:1)
s3_path = "s3://folder1/folder2/folder3/folder4/folder4.5/folder4.6/folder5/folder6/folder7/file_name.csv"
s3_path_split = s3_path.split('/')
bucket_name = s3_path_split[2]
# 'folder1'
key_name = '/'.join(s3_path_split[3:])
# 'folder2/folder3/folder4/folder4.5/folder4.6/folder5/folder6/folder7/file_name.csv'
key_name_without_file = '/'.join(s3_path_split[3:-1])
# folder2/folder3/folder4/folder4.5/folder4.6/folder5/folder6/folder7'