当前位置:网站首页>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
边栏推荐
- What you should know about futures account opening
- Substrate 源码更新导读八月第1周: 新版事务化存储层启用默认模式, Polkadot v0.9.27发布
- How tall is the B+ tree of the MySQL index?
- BSN季度版本2022年8月31日迭代更新预告
- 华为云全流程护航《流浪方舟》破竹首发,打造口碑爆款
- International Soil Modeling Consortium-ISMC
- What is control board custom development?
- 【Pycharm好用功能】
- crm系统哪家好?好用的crm管理系统推荐
- 50道Redis面试题,来看看你会多少?
猜你喜欢
微服务:事务管理
How to adjust futures account opening process and handling fee
[极客大挑战 2019]HardSQL
方舟:生存进化开服务器端口映射教程
.NET 6 study notes (4) - Solve the Nullable warning in VS2022
[Pycharm easy to use function]
An in-depth understanding of the implementation principle of Hybrid
最强分布式锁工具:Redisson
2022 全球 AI 模型周报
《.NET物联网从零开始》系列
随机推荐
Experience far more than Hue, this is the favorite SQL tool for technicians
SkiaSharp 之 WPF 自绘 粒子花园(案例版)
字节也开始缩招了...
JVM内存模型和结构详解(五大模型图解)
About the common Hook encapsulation of DOM (2)
Apache Doris Community PMC Yang Zhengguo: How do open source projects strike a balance between their own and the community's needs?
动态RDLC报表(二)
【时序数据库InfluxDB】Windows环境下配置InfluxDB+数据可视化,以及使用 C#进行简单操作的代码实例...
openEuler 熊伟:如何看待开源社区中的 SIG 组织模式?
神秘的程序员(20-30)
Fees and inquiry methods of futures account opening exchanges
手写flexible.js的原理实现,我终于明白移动端多端适配
重谈联想5G编码投票事件
Detailed explanation of JVM memory model and structure (five model diagrams)
【代码审计】——PHP项目类RCE及文件包含下载删除
How tall is the B+ tree of the MySQL index?
自学软件测试,学到什么程度可以出去找工作啊?
uniapp电影购票选座系统源码
【.NET6+Modbus】Modbus TCP协议解析、仿真环境以及基于.NET实现基础通信
leetcode300.最长递增子序列(动态规划)