当前位置:网站首页>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边栏推荐
- Volatile: JVM I warn you, my people don't move
- JMeter笔记6 | JMeter录制(配置代理)
- 字节也开始缩招了...
- [Pycharm easy to use function]
- .NET 6 study notes (4) - Solve the Nullable warning in VS2022
- Detailed explanation of JVM memory model and structure (five model diagrams)
- 在 ASP.NET Core 中上传文件
- openEuler 熊伟:如何看待开源社区中的 SIG 组织模式?
- .NET Community Toolkit 8.0.0 版本发布
- 【机器学习】回归树生成过程及举例理解
猜你喜欢

Lagrange interpolation formula matlab implementation

测试开发是什么,为什么现在这么吃香?

crm系统哪家好?好用的crm管理系统推荐
试试使用 Vitest 进行组件测试,确实很香。

The principle implementation of handwritten flexible.js, I finally understand the multi-terminal adaptation of the mobile terminal

一文深入了解 Hybrid 的实现原理

学长告诉我,大厂MySQL都是通过SSH连接的

动手学深度学习_全卷积网络 FCN

方舟:生存进化开服务器端口映射教程

论如何提升学习的能力
随机推荐
重谈联想5G编码投票事件
Tan Zhongyi: Do you know who the "Queen of Open Source" is?
华为云全流程护航《流浪方舟》破竹首发,打造口碑爆款
Metasploit——辅助模块(Auxiliary)
微软 .NET Core 3.1 年底将结束支持,请升级到.NET 6
太细了!阿里大佬耗时39天整理出一份Redis进阶笔记,满满的干货
自学软件测试,学到什么程度可以出去找工作啊?
无需支付688苹果开发者账号,xcode13打包导出ipa,提供他人进行内测
The strongest distributed lock tool: Redisson
.NET 6 study notes (4) - Solve the Nullable warning in VS2022
The most complete architect knowledge map in history
怎样选择一个好的SaaS知识库工具?
leetcode/链表中环的入口节点
动态RDLC报表(二)
.NET 6学习笔记(4)——解决VS2022中Nullable警告
最强分布式锁工具:Redisson
【ROS2原理9】 QoS - 截止日期、活跃度和寿命
[极客大挑战 2019]HardSQL
如何仿造一个websocket请求?
动态RDLC报表(四)