0

我想列出 azure 容器中唯一的上周数据。我使用的 python 代码首先列出了整个数据,然后根据给定的if 条件对其进行过滤。

list1 = [a.name for a in container_client.list_blobs(name_starts_with='folder1/') if a.last_modified.date() in last_week]

此命令所花费的时间随着 folder1 大小的增加而增加,那么他们有什么方法可以更有效地获取此列表吗?

4

1 回答 1

0

谢谢Anupam ChandMustafa Salam。发布您的建议作为帮助其他社区成员的答案。

这不能由 SDK(.NET 或 Python)或 Rest API 完成,但目前只能由PowerShell完成。该答案还提供了在文件名前加上日期前缀的替代方法,以便您可以使用“name_starts_with”参数查询它们。

您可以使用PowerShell根据日期列出 Azure 容器中的 blob :

$StorageAccountName = "AccountName" 
$StorageAccountKey = "What_ever_your_key_is_123asdf5524523A=="
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$ContainerName = "Container"

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt (Get-Date).Date}

获取日期


$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt ((Get-Date).Date).AddDays(-1)}

排序对象

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt (Get-Date).Date.AddDays(-1)} `
| Sort-Object -Property Date

您可以参考Is it possible to List Azure Blobs Where Last Modified Date > Some Date有没有办法根据时间戳列出 AzureBlobStorage 中的 blob?获取某个日期后添加的容器中的 blob 列表

于 2021-09-15T04:27:30.507 回答