基本上,我有这段代码:
DirectoryInfo dir = new DirectoryInfo(@"\\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL\00806\");
FileInfo[] files = dir.GetFiles("200810*");
我希望它匹配任何以 200810 开头的文件。但是,它匹配名为
的文件20070618_00806.bak 和 20070817_00806.bak(星星不在文件名中,这是我可以包含下划线的唯一方式)
我在命令提示符下用 dir 试了一下,它也匹配那些文件。为什么?
编辑:
也许使用 C: 作为示例并不是一件好事。我实际查询的目录是网络共享 \\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL\00806\
如果检查短名称有什么关系,20070817_00806.bak会不会是200708~1.bak?那也不匹配
最佳答案
msdn指出
"Because this method checks against file names with both the 8.3 file name format and the long file name format, a search pattern similar to "
*1*.txt
" may return unexpected file names. For example, using a search pattern of "*1*.txt
" will return "longfilename.txt
" because the equivalent 8.3 file name format would be "longf~1.txt
"."
会不会是这个原因?
关于c# - 为什么 DirectoryInfo.GetFiles() 匹配与掩码不匹配的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/786278/