删除Azure Blob存储容器中的文件夹 [英] Delete folder(s) inside Azure Blob storage container

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

问题描述

我有一个名为图片" 的容器,并且其中有一些名为"Folder1","Folder2" 的文件夹.因此,我的Blob文件将像这样" http://optimus.blob.core.windows.net/pictures/Folder1/IMG123.png ".使用下面的C#代码删除文件夹中的文件

I have a container named "pictures", and have some folders named "Folder1", "Folder2" inside of it. So files of my blob will be addressed like this "http://optimus.blob.core.windows.net/pictures/Folder1/IMG123.png". Using the below C# code to delete the files inside folders,

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(*AzureConnectionString*);

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer container = blobClient.GetContainerReference("pictures");

var blobs = container.ListBlobs("Folder1", true);
foreach (var blob in blobs)
{
  container.GetBlockBlobReference(((CloudBlockBlob)blob).Name).DeleteIfExists();
}

删除"Folder1" 中的所有那些文件后,它将为空.我正在尝试删除空文件夹,但无法解决该问题.是否可以删除文件夹?任何帮助都感激不尽.预先感谢.

after deleting all those files in "Folder1" it will be empty. I m trying to delete the empty folder, but can't get a way to do it. Is it possible to delete the folder(s)? Any help will be much appreciated. Thanks in advance.

推荐答案

在任何blob容器下,都不存在实际的文件夹或目录.它们是虚拟目录,用于管理容器下Blob的文件夹结构,并且如果删除了具有任何虚拟目录或文件夹的所有Blob,则不存在此类文件夹.都是文件夹结构的逻辑表示,您可以忽略任何容器下的文件夹.

Under any blob container, there is no real folder or directory exists. They are virtual directories to manage the folder structure for the blobs under container and if all the blobs with any virtual directory or folder are deleted then no such folder exists. It is all logical representation of folder structure and you can ignore the folders under any container.

但是关于容器,如果要清理整个容器,则还需要在删除其blob之后手动删除该容器.

But when it comes to container, you need to manually delete the container as well after deleting its blobs, if you want to clean up the whole container.

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

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