[英]How to get a list of blobs in a sub container in Azure
我需要使用 url 從存儲中獲取所有文件:“https://example.blob.core.windows.net/file/subfile1/subfile2”我只需要讀取數據文件(例如 only.txt,所以如果我有.jpg 或其他我應該跳過的內容)並且僅來自 subfile2,而不是整個存儲。
與 c# 順便說一句
我嘗試在我的系統中下載容器子文件夾中的所有txt文件( test 是容器,test1 是容器中的文件夾),試試這個代碼。
using Microsoft.Azure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
namespace listtxtblobs
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Connection string");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("test//container name");
List<string> blobnames = new List<string>();
var allblobs = container.ListBlobs(useFlatBlobListing: true);
foreach (var b in allblobs)
{
string name = ((CloudBlockBlob)b).Name;
Console.WriteLine(name);
string[] names = name.Split('/');
blobnames.Add(names[names.Length - 1]);
}
foreach(string name in blobnames)
{
Console.WriteLine(name);
if (name.Contains(".txt"))
{
string filePath = "local file path\\" + name;
CloudBlockBlob blockBlob = container.GetBlockBlobReference("test1\\"+ name);
blockBlob.DownloadToFile(filePath, FileMode.OpenOrCreate);
}
}
}
}
}
azure存儲中的文件夾結構
OUTPUT
下載本地文件夾中的所有txt文件
有不同版本的工作樣本
V11 對我有用(由於.Net 版本限制,我需要使用這個)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.