当前位置:网站首页>win10 uwp 获取指定的文件 AQS
win10 uwp 获取指定的文件 AQS
2022-08-09 16:53:00 【林德熙】
很多时候不需要获取整个文件夹的文件,是需要获取文件夹里指定的文件。 那么 UWP 如何对文件夹里的文件进行过滤,只拿出自己需要的文件? 本文:如何使用通配符或文件匹配方式在uwp获取文件夹中指定的文件
假如需要文件 有前缀”latest_” ,简单的方法是拿出 文件夹所有的文件,使用简单的对比,但是这样需要获取文件夹所有文件,速度比较慢。
var previousInfo = (await rootFolder.GetFilesAsync()).Where(file => file.DisplayName.StartsWith("latest_")).FirstOrDefault();
一个好的方法是使用 Advanced Query Syntax
第一步,新建QueryOptions
var queryOptions = new QueryOptions();
queryOptions.ApplicationSearchFilter = "System.FileName:latest_*";
上面的 ApplicationSearchFilter 就是根据 Using Advanced Query Syntax Programmatically (Windows) 写出对应判断
然后从当前的 文件夹 获取匹配
StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(queryOptions);
最后就是从结果拿出文件
var files = await queryResult.GetFilesAsync();
参见:http://stackoverflow.com/a/43829407/6116637
UWP 获取指定后缀的文件
修改上面的 ApplicationSearchFilter 为下面格式就可以获得后缀
System.FileExtension:=".后缀"
如获取 txt 可以使用
queryOptions.ApplicationSearchFilter = "System.FileExtension:=\".txt\"";
设置后缀除了上面的方法,可以使用简单的设置
var queryOptions = new QueryOptions();
queryOptions.FileTypeFilter.Add(".txt");
除了后缀,还可以设置文件大小
System.Size:
System.Size: <1kb
如果有多个判断,使用 and 连接或 or 连接,但是关于他的语法文档很少。
如果需要的搜索是包括子文件夹的内容,请设置 queryOptions.FolderDepth
queryOptions.FolderDepth = FolderDepth.Deep
边栏推荐
- API接口是什么?API接口常见的安全问题与安全措施有哪些?
- 国际土壤模型协会 International Soil Modeling Consortium-ISMC
- openEuler Xiong Wei: How do you view the SIG organization model in the open source community?
- .NET 6学习笔记(4)——解决VS2022中Nullable警告
- 动态RDLC报表(五)
- 如何仿造一个websocket请求?
- C#介绍及基本数据类型
- 2022秋招面试宝典,啃完面试稳了
- .NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
- Jenkins deploys services to remote servers using pipelines
猜你喜欢
谭中意:你知道 “开源女王” 是谁吗?
In-depth understanding of MySQL common data types and data type selection optimization
Account opening requirements and exemptions for special futures such as crude oil
基于CAP组件实现补偿事务与幂等性保障
秋招面试大厂总被刷下来,你这样做保准你事半功倍!
Discuz! Forum program installation + template configuration tutorial
史上最全架构师知识图谱
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
The strongest distributed lock tool: Redisson
为了高性能、超大规模的模型训练,这个组合“出道”了
随机推荐
50道Redis面试题,来看看你会多少?
SkiaSharp 之 WPF 自绘 投篮小游戏(案例版)
2022 全球 AI 模型周报
基于CAP组件实现补偿事务与幂等性保障
win10 uwp 无法附加到CoreCLR
EPIC是什么平台?
Ark: Survival Evolved Open Server Port Mapping Tutorial
What is test development and why is it so popular now?
MASA Stack 第三期社区例会
Prometheus完整安装
动态RDLC报表(二)
Tan Zhongyi: Do you know who the "Queen of Open Source" is?
记一次 .NET 某工控自动化控制系统 卡死分析
史上最全架构师知识图谱
【工业数字化大讲堂 第二十一期】企业数字化能碳AI管控平台,特邀技术中心总经理 王勇老师分享,8月11日(周四)下午4点
mysql generates random name, mobile number, date
What you should know about futures account opening
Experience far more than Hue, this is the favorite SQL tool for technicians
Entry node of ring in leetcode/linked list
Lagrange interpolation formula matlab implementation