简体   繁体   English

DirectoryInfo.getFiles始于

[英]DirectoryInfo.getFiles beginning with

I've come across some strange behavior trying to get files that start with a certain string. 我遇到了一些奇怪的行为,试图获取以某个字符串开头的文件。

Please would someone give a working example on this: 请有人对此提供一个可行的示例:

I want to get all files in a directory that begin with a certain string, but also contain the xml extension. 我想获取目录中以某个字符串开头的所有文件,但还包含xml扩展名。

for example: 例如:

 apples_01.xml
 apples_02.xml
 pears_03.xml

I want to be able to get the files that begin with apples. 我希望能够获取以苹果开头的文件。

So far I have this code 到目前为止,我有这段代码

 DirectoryInfo taskDirectory = new DirectoryInfo(this.taskDirectoryPath);
 FileInfo[] taskFiles = taskDirectory.GetFiles("*.xml");
FileInfo[] taskFiles = taskDirectory.GetFiles("apples*.xml");
var taskFiles = taskDirectory.GetFiles("*.xml").Where(p => p.Name.StartsWith("apples"));

GetFiles list files based on Search Pattern you applied. GetFiles根据您应用的搜索模式列出文件。

Please refer to DirectoryInfo.GetFiles to know about how to use Search Pattern. 请参考DirectoryInfo.GetFiles以了解如何使用搜索模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM