gpt4 book ai didi

python - 有没有办法根据时间戳列出 AzureBlobStorage 中的 blob?

转载 作者:行者123 更新时间:2023-12-02 07:55:39 24 4
gpt4 key购买 nike

我想以编程方式列出特定时间后在 Azure 存储容器中创建的所有 Blob?有没有办法只列出那些 blob 文件?

最佳答案

目前,没有直接的方法可以在一定时间后列出 blob。

这里有 2 个解决方法。

1.先列出所有blob -> 获取每个blob的创建时间 -> 将blob的创建时间与特定时间进行比较。如下所示:

myblobs = container_client.list_blobs()

#define a filter date or timestamp as per your need.
filter_date = "2021-01-18 or 2021-01-18 01:31:29"

for blob in myblobs:
#compare the creation time of blob with the filter_date
if str(blob.creation_time) > filter_date:
print(blob.name + ":" + str(blob.creation_time))

2.创建 Blob 时,您可以为 Blob 指定前缀。前缀可以定义为年-月-日(或者您可以添加小时、分钟等)。然后,当您使用 list_blobs() 方法列出 blob 时,会有一个参数 name_starts_with。此时,您可以为 name_starts_with 参数指定日期。

关于python - 有没有办法根据时间戳列出 AzureBlobStorage 中的 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66284800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com