如何递归装入Azure的BLOB文件列表? [英] How to load list of Azure blob files recursively?

查看:450
本文介绍了如何递归装入Azure的BLOB文件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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方法,它接受两个参数:

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:


  1. preFIX :这是你的目录的名称。如果它是一个嵌套的目录,则需要例如指定完整路径MyFolder中/ mysubfolder。

  2. useFlatBlobListing :这个值设置为真正将确保只有斑点返回(包括目录中所有子文件夹中)而不是目录和斑点。

  1. 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.
  2. 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屋!

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