[英]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.