【发布时间】:2020-03-11 21:37:02
【问题描述】:
我的 Azure Blob 容器包含两个虚拟文件夹 A 和 B,以及一些文件。我在我的项目中使用此代码来下载本地文件夹中容器的内容:
private async void Test(string temp, CloudBlobContainer container, string target, string prefix) {
foreach (var item in container.ListBlobs(prefix)) {
switch (item) {
case CloudBlobDirectory directory:
Directory.CreateDirectory(Path.Combine(temp, directory.Prefix));
Test(Path.Combine(temp, directory.Prefix), container, target, directory.Prefix);
break;
}
}
await CopyAll(temp, target, controller); /* Just a function to call at the end of the method*/
}
拥有一个具有这种虚拟结构的容器:
container
A/
B/
one.txt
two.txt
...
我想在本地文件夹上复制相同的结构。问题是 B 被跳过 并且 foreach 只考虑 A,但是如果我将 Test(Path.Combine(temp, directory.Prefix), container, target, directory.Prefix) 替换为例如 System.Diagnostics.Debug.WriteLine(directory.Prefix) 以仅打印它们,则 B 被打印到控制台。很明显递归存在问题,但我看不到它。我使用递归来遍历容器中的虚拟目录,以便将原始结构复制到本地文件夹中。
【问题讨论】:
标签: c# recursion azure-blob-storage