将整个文件夹上传到Azure blob上的特定文件夹

der*_*rek 0 azure-storage-blobs azure-powershell

我知道如何将整个文件夹上传到Azure blob上的一个容器,就是这样:

Get-ChildItem -File -Recurse | Set-AzureStorageBlobContent -Container $ContainerName -Context $ctx
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果我的容器下面有一个文件夹,说它是“测试”。如何将本地文件夹中的所有文件/子文件夹上载到Azuure Blob mycontainer / test /。

谢谢

小智 5

要在容器中创建文件夹,我们只需要使用路径名和文件名的组合作为Blob名称。

Get-ChildItem返回的对象具有名为FullName的属性。然后我们可以使用substring方法删除磁盘字母。

Get-ChildItem -File -Recurse C:\Test\ | ForEach-Object { Set-AzureStorageBlobContent -File $_.FullName -Blob $_.FullName.Substring(3) -Container uploaded -Context $ctx }
Run Code Online (Sandbox Code Playgroud)

这是我的实验室的屏幕截图:

实验室