【问题标题】:Azure File Storage - List directory contents - read filenamesAzure 文件存储 - 列出目录内容 - 读取文件名
【发布时间】:2018-10-19 14:14:16
【问题描述】:

这听起来像是一项最简单的任务,我要做的只是列出 Azure 文件存储共享下的子目录的内容,我设法获得了“CloudFileDirectory”然而,对象正在努力阅读其内容。

我仅限于在 PowerShell 中编写此解决方案,因此使用名为“AzureRM”的 PS 模块,如下所示:

# Install AzureRM module & check if installed:
Install-Module -Name "AzureRM"
Get-Module -Name AzureRM -List | select Name,Version

# Import module in session:
Import-Module AzureRM

# Connect/sign-on to Azure account (interactive login):
Connect-AzureRmAccount

# Get reference to Storage account:
$storageAcct = Get-AzureRmStorageAccount -ResourceGroupName "myRSG" -AccountName "myCloudStorage"

#Get directory object:
$objDir = Get-AzureStorageFile -Context $storageAcct.Context -ShareName "myShare" -Path "myFolder1"

我被这个 ($objDir) 对象困住了,它基本上是一个 WindowsAzure.Storage.File.CloudFileDirectory 对象,但不像通常的目录对象,因为它似乎不包含集合(见下面的输出):

$objDir.GetType().FullName           #-> "WindowsAzure.Storage.File.CloudFileDirectory" object
$objDir | % {$_.GetType().FullName}  #-> "WindowsAzure.Storage.File.CloudFileDirectory" object

基本上,我需要读取此子文件夹中的文件名。我将不胜感激。 TIA。

【问题讨论】:

  • 尝试类似下面的方法来列出文件:Get-AzureStorageFile -Context $storageAcct.Context -ShareName "myShare" -Path "myFolder1" | Get-AzureStorageFile.
  • 太好了,谢谢 Gaurav,我现在得到了一个集合(虽然我可以迭代)。太棒了,再次感谢您的快速回答。

标签: .net azure powershell cloud


【解决方案1】:

(根据 Gaurav 的评论)额外添加一个 | Get-AzureStorageFile 解决了这个问题并返回了预期的输出,即我现在得到了一个集合/数组 (System.Object[]),我通过它来获取个人文件名及其各自的大小,这是我现在得到的代码+输出和对象类型:

#Get directory object:
$objDir = Get-AzureStorageFile -Context $storageAcct.Context -ShareName "myShare" -Path "myFolder1" | Get-AzureStorageFile
$objDir.GetType().FullName            #-> "System.Object[]" object
$objDir  | % {$_.GetType().FullName}  #-> "WindowsAzure.Storage.File.CloudFile / CloudDirectory" objects
$objDir  | % {$_} | select Name,StreamMinimumReadSizeInBytes

输出

Name      StreamMinimumReadSizeInBytes
----      ----------------------------
file.txt                       4194304
file1.txt                      4194304
foo.txt                        4194304

【讨论】:

    猜你喜欢
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    相关资源
    最近更新 更多