如何删除Azure Blob容器中的文件夹
我在Azure中有一个名为pictures
的Blob容器,其中有多个文件夹(请参见下面的快照):
I have a blob container in Azure called pictures
that has various folders within it (see snapshot below):
我正在尝试删除快照中显示的名为users
和uploads
的文件夹,但出现错误: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").