Python 遍历中国区 s3 目录(qbit)

  • SDK 版本
Python 3.9
s3fs  2021.7.0
# coding: utf-8
# author: qbit
# date: 2021-08-08
# summary: 遍历中国区 S3 目录

import s3fs

# 如果操作系统已配置命令行可访问 s3
# 可以不用参数
fs = s3fs.S3FileSystem(
    key="aws_access_key_id",
    secret="aws_secret_access_key",
    client_kwargs={"region_name": "cn-northwest-1"}     # 中国宁夏区
)

print(fs.ls("qbit-cn-northwest-1"))
for parent, dirs, files in fs.walk("qbit-cn-northwest-1/data"):
    for file in files:
        pathfile = f"{parent}/{file}"
        print(f"{fs.size(pathfile)/1024:8.2f} KB {pathfile}")
本文出自 qbit snap

你可能感兴趣的:(Python 遍历中国区 s3 目录(qbit))