【发布时间】:2016-02-26 08:57:06
【问题描述】:
我正在使用以下代码:
var di = new DirectoryInfo("path/to/dir");
var matchingFiles = di.GetFiles("*.???);
正如预期的那样,文件像
- file.bat
- test.1.xml
- a.txt.txt
被退回。然而,有一些有趣的结果。正如the MS-documentation 提到的,短名称也被搜索。我还找到了the information about the dot-selector working in .NET 4+。我仍然看不到这解释了以下结果:
- file1.xml.2
- 没有扩展名的文件
Q1:如何解释这个结果。
Q2:如何实现模式*.[3个任意字符]的匹配。
【问题讨论】:
-
尝试添加
SearchOption.TopDirectoryOnly:Directory.GetFiles("path/to/dir", "*.???",SearchOption.TopDirectoryOnly)
标签: c# .net directory filenames