如何递归装入Azure的BLOB文件列表? [英] How to load list of Azure blob files recursively?
问题描述
Azure的BLOB文件存储在一个普通的名单没有任何物理文件夹结构,但是我们可以创建虚拟文件夹,每个文件的文件夹路径是它的名字的一部分。
Azure blob files are stored in a plain list without any physical folder structure, but we can create virtual folders where each file's folder path is a part of it's name.
它带来了另一个问题,如何检索虚拟子文件夹中的所有文件的列表中,仅使用文件夹的名称?
It brings out another problem, how to retrieve a list of ALL files in virtual sub-folder, using only that folder's name?
推荐答案
其实,有做一个简单的方法,它是在库本身提供。如果你看一下<一个href=\"https://msdn.microsoft.com/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx\"><$c$c>CloudBlobContainer.ListBlobs$c$c>方法,它接受两个参数:
Actually, there's a simpler way to do that and it is available in the library itself. If you look at CloudBlobContainer.ListBlobs
method, it accepts two parameters:
- preFIX :这是你的目录的名称。如果它是一个嵌套的目录,则需要例如指定完整路径MyFolder中/ mysubfolder。
-
useFlatBlobListing :这个值设置为
真正
将确保只有斑点返回(包括目录中所有子文件夹中)而不是目录和斑点。
- prefix: This is the name of your directory. If it is a nested directory, you will need to specify the full path e.g. myfolder/mysubfolder.
useFlatBlobListing: Setting this value to
true
will ensure that only blobs are returned (including inside any sub folders inside that directory) and not directories and blobs.
var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("blob-container-name");
var blobs = container.ListBlobs(prefix: "container-directory", useFlatBlobListing: true);
您将获得斑点
变量的容器目录,属于所有的blob的列表。
You will get a list of all blobs belonging in the "container-directory" in blobs
variable.
这篇关于如何递归装入Azure的BLOB文件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!