我遇到了一些奇怪的行为,试图获取以某个字符串开头的文件.
请有人就此提供一个有效的例子:
我想获取一个以某个字符串开头的目录中的所有文件,但也包含xml扩展名.
例如:
apples_01.xml
apples_02.xml
pears_03.xml
Run Code Online (Sandbox Code Playgroud)
我希望能够获得以苹果开头的文件.
到目前为止,我有这个代码
DirectoryInfo taskDirectory = new DirectoryInfo(this.taskDirectoryPath);
FileInfo[] taskFiles = taskDirectory.GetFiles("*.xml");
Run Code Online (Sandbox Code Playgroud)
Cer*_*rus 42
FileInfo[] taskFiles = taskDirectory.GetFiles("apples*.xml");
Run Code Online (Sandbox Code Playgroud)
var taskFiles = taskDirectory.GetFiles("*.xml").Where(p => p.Name.StartsWith("apples"));
Run Code Online (Sandbox Code Playgroud)