如何删除Azure Blob容器中的文件夹 [英] How to delete a folder within an Azure blob container

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

问题描述

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

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

我正在尝试删除快照中显示的名为usersuploads的文件夹,但出现错误:Failed to delete blob pictures/uploads/. Error: The specified blob does not exist.有人可以阐明如何删除这两个文件夹吗?我一直无法通过Google搜索这个问题来发现任何有意义的东西.

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存储不具有文件夹的概念.层次结构非常简单:存储帐户>容器> blob .实际上,删除特定文件夹就是删除所有以文件夹名称开头的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容器中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆