如何在 Windows Phone 运行时获取 StorageFolder 中的所有文件? [英] How to get all files in a StorageFolder in Windows Phone Runtime?

查看:29
本文介绍了如何在 Windows Phone 运行时获取 StorageFolder 中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to get all files in a folder and its sub folders. but a flat query like this:

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

抛出一个 ArgumentException 异常:

发生了System.ArgumentException"类型的第一次机会异常

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

附加信息:值不在预期范围内.

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

在我一一查询子文件夹之前,没有其他办法了吗?

before I query subfolders one by one, isn't there any other way?

推荐答案

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

You want all the files and folder which are a descendent of the root folder, not just the shallow enummeration. For most folders the only way to enumerate all the contents and its subfolders content is:

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

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

There is a workaround for this if you are looking for a particular type of media. The instructions are here. These few combinations of locations and CommonFile/FolderQuery options will give a device deep search for media and return the ordered results.

这篇关于如何在 Windows Phone 运行时获取 StorageFolder 中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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