使用 powershell 仅选择 Azure 容器中的“父文件夹”

问题描述 投票:0回答:1

我有一个Azure容器,该容器包含文件夹(还包含子文件夹和文件)和文件。我只想要“父文件夹”,所以只需要打开容器时看到的文件夹,但是我无法使用 $blobs = Get-AzStorageBlob 正确获取它。因为当我遍历 blob 时,它会为我提供容器中的所有内容。

希望有人能帮助我。预先感谢。

亲切的问候

$blobs = Get-AzStorageBlob -Context $context -Container $container.Name
foreach ($blob in $blobs) {
     write-host $blob.Name
}
azure powershell directory containers blob
1个回答
0
投票

Azure Blob 存储有虚拟文件夹的概念。它们不是真正的文件夹,只是路径元素。所以类似下面的 PowerShell 应该可以做到。

$blobs = Get-AzStorageBlob -Context $context -Container $container.Name
foreach ($blob in $blobs) {
    if (($blob.name).Split('/').Length -gt 1) {
        Write-Host ($blob.name).Split('/')[0]
    }
}

下面的此链接提到了 ADLS Gen2,如果您需要更多“真实”文件夹,您可能需要它。 https://learn.microsoft.com/en-us/answers/questions/1306036/controlling-access-to-files-using-virtual-director

这是我能找到的有关虚拟文件夹概念的最佳参考。如果您使用存储资源管理器创建的,您可能会使用“/”字符作为分隔符,但看起来您可以拥有任何内容。 https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-list#flat-listing-versus-hierarchical-listing

© www.soinside.com 2019 - 2024. All rights reserved.