简体   繁体   English

如何使用新的 Azure.Storage.Blobs 命名空间仅获取 blob 中的文件夹名称

[英]How to get only folder name in blob using new Azure.Storage.Blobs namespace

快照

I want to get all the folder name under a container using new SDK - Azure.Storage.Blobs我想使用新的 SDK - Azure.Storage.Blobs 获取容器下的所有文件夹名称

You would want to use GetBlobsByHierarchy method in BlobContainerClient class and pass "/" as prefix.您可能希望在BlobContainerClient class 中使用GetBlobsByHierarchy方法并将“/”作为前缀传递。 The method will return all the blobs and folders at the root level.该方法将返回根级别的所有 blob 和文件夹。 Once you get that, you will simply need to filter out the blobs by selecting only the items from the result where IsPrefix property is true (or you could check for Blob property to be null ).一旦你得到它,你将只需要通过仅从结果中选择IsPrefix属性为 true 的项目来过滤掉 blob(或者你可以检查Blob属性是否为null )。

Please try something like the following:请尝试以下操作:

        var connectionString = "DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account-key>;EndpointSuffix=core.windows.net;";
        var containerName = "test";
        var containerClient = new BlobContainerClient(connectionString, containerName);
        var blobFolders = containerClient.GetBlobsByHierarchy(BlobTraits.None, BlobStates.None, "/").Where(b => b.IsPrefix).ToList();
        for (var i=0; i<blobFolders.Count; i++)
        {
            Console.WriteLine("Folder Prefix: " + blobFolders[i].Prefix);
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 想要使用新的 sdk - Azure.Storage.Blobs package 从 blob 内的文件夹下载和上传文件 - Want to download and upload file from a folder inside the blob using new sdk - Azure.Storage.Blobs package 使用新的 Azure.Storage.Blobs 时如何计算存储帐户中 Blob 存储容器的总大小 - How to calculate the total size of Blob storage containers in an storage account when using the new Azure.Storage.Blobs 如何使用 C# 中的 Azure.Storage.Blobs 以 ByteArray 格式从 Azure 存储 blob 中获取文件 - How to get file from Azure storage blob in a ByteArray format using Azure.Storage.Blobs in C# 使用 Azure.Storage.Blobs 枚举大型 Azure BLOB 容器 - Enumerating large Azure BLOB containers using Azure.Storage.Blobs 如何使用 Azure.Storage.Blobs BlobClient 检索 blob 目录路径中的 blob? - How to retrieve blobs within a blob directory path using the Azure.Storage.Blobs BlobClient? 有没有办法在 Azure.Storage.Blobs 中获取 blob 的 ContentType? - Is there a way to get a blob's ContentType in Azure.Storage.Blobs? 如何使用 Azure.Storage.Blobs 程序集对 Azure blob 存储操作设置重试策略? - How do I set a retry policy on an Azure blob storage operation using the Azure.Storage.Blobs assembly? Azure.Storage.Blobs 文件夹结构 - Azure.Storage.Blobs Folder Structure 如何模拟 Azure.Storage.Blobs 的 BlobContainerClient()? - How to Mock BlobContainerClient() of Azure.Storage.Blobs? 如何使用 Azure.Storage.Blobs 上传 stream - How to upload stream with Azure.Storage.Blobs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM