Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有一种方法可以根据时间戳列出AzureBlobStorage中的Blob?_Python_Azure_Azure Blob Storage - Fatal编程技术网

Python 有没有一种方法可以根据时间戳列出AzureBlobStorage中的Blob?

Python 有没有一种方法可以根据时间戳列出AzureBlobStorage中的Blob?,python,azure,azure-blob-storage,Python,Azure,Azure Blob Storage,我想以编程方式列出特定时间后在Azure存储容器中创建的所有Blob?有没有办法只列出那些blob文件?如果您喜欢Powershell: $daysAgo = 30 # this example uses OAuth token, you can change it to use a SAS token or account key $ctx = New-AzStorageContext -StorageAccountName MyStorageAccount -UseConnectedAcco

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

如果您喜欢Powershell:

$daysAgo = 30
# this example uses OAuth token, you can change it to use a SAS token or account key
$ctx = New-AzStorageContext -StorageAccountName MyStorageAccount -UseConnectedAccount

# Get all blobs in container, get the Name and CreatedOn date
# then filter by days old and sort by descending date
Get-AzStorageBlob -Context $ctx -Container MyContainer | `
  Select-Object Name, @{L="CreatedOn"; E={$_.BlobProperties.CreatedOn}} | `
  Where-Object CreatedOn -gt (Get-Date).AddDays(-$daysAgo) | `
  Sort-Object CreatedOn -Descending

重要提示:您必须是该帐户上的存储帐户Blob参与者。我是订阅所有者,但在我添加此角色之前,这在我的帐户上不起作用。可能还有其他角色可以工作,但不要假设您的订阅或资源组级别的角色在这里可以工作。

目前,没有直接的方法在特定时间后列出blob

这里有两个变通办法

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\u blobs()
方法列出blob时,有一个参数
name\u以
开头。此时,您可以使用参数指定
name\u start\u的日期。

我正在查看python或SDK支持。谢谢因为这个问题是开放式的,所以我选择了我的武器。可能想让其他人知道这个问题!您好,如果答案有帮助,请接受它作为答案。谢谢