删除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.