gpt4 book ai didi

c# - 如何在 Windows Phone 运行时获取 StorageFolder 中的所有文件?

转载 作者:行者123 更新时间:2023-11-30 14:29:47 24 4
gpt4 key购买 nike

我想获取文件夹及其子文件夹中的所有文件。但是像这样的平面查询:

var allFiles = await myFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName);

抛出一个ArgumentException异常:

A first chance exception of type 'System.ArgumentException' occurred

Additional information: Value does not fall within the expected range.

在我一个一个查询子文件夹之前,有没有别的办法?

最佳答案

您需要所有作为根文件夹后代的文件和文件夹,而不仅仅是浅枚举。对于大多数文件夹,枚举所有内容及其子文件夹内容的唯一方法是:

  1. 对文件使用 StorageFolder.GetFilesAsync()
  2. 使用 StorageFolder.GetFoldersAsync() 检索所有子文件夹
  3. 对您在第 2 步中找到的所有子文件夹递归重复。

如果您正在寻找特定类型的媒体,则有一个解决方法。说明是here .这几个位置和 CommonFile/FolderQuery 选项的组合将使设备能够深入搜索媒体并返回有序结果。

关于c# - 如何在 Windows Phone 运行时获取 StorageFolder 中的所有文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25102610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com