本文介绍了如何删除 Azure blob 容器中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Azure 中有一个名为 pictures 的 blob 容器,其中包含多个文件夹(请参阅下面的快照):

I have a blob container in Azure called pictures that has various folders within it (see snapshot below):

我正在尝试删除快照中显示的标题为 usersuploads 的文件夹,但我保留了错误:无法删除 blob 图片/上传/.错误:指定的 blob 不存在. 谁能解释一下我如何删除这两个文件夹?通过谷歌搜索这个问题,我没有发现任何有意义的东西.

I'm trying to delete the folders titled users and uploads shown in the snapshot, but I keep the error: Failed to delete blob pictures/uploads/. Error: The specified blob does not exist. Could anyone shed light on how I can delete those two folders? I haven't been able to uncover anything meaningful via Googling this issue.

注意:如果需要,请向我索取更多信息

推荐答案

Windows Azure Blob Storage 没有文件夹的概念.层次结构非常简单:存储帐户>容器 >斑点.事实上,删除特定文件夹就是删除所有以文件夹名称开头的 blob.您可以编写如下简单的代码来删除您的文件夹:

Windows Azure Blob Storage does not have the concept of folders. The hierarchy is very simple: storage account > container > blob. In fact, removing a particular folder is removing all the blobs which start with the folder name. You can write the simple code as below to delete your folders:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("your storage account");
CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("pictures");
foreach (IListBlobItem blob in container.GetDirectoryReference("users").ListBlobs(true))
{
    if (blob.GetType() == typeof(CloudBlob) || blob.GetType().BaseType == typeof(CloudBlob))
    {
        ((CloudBlob)blob).DeleteIfExists();
    }
}

container.GetDirectoryReference("users").ListBlobs(true) 列出以users"开头的 blob;在图片"内容器,然后您可以单独删除它们.要删除其他文件夹,您只需要像这样指定GetDirectoryReference(您的文件夹名称").

container.GetDirectoryReference("users").ListBlobs(true) lists the blobs start with "users" within the "picture" container, you can then delete them individually. To delete other folders, you just need to specify like this GetDirectoryReference("your folder name").

这篇关于如何删除 Azure blob 容器中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:37