Basically, I have this code:
基本上,我有这个代码:
DirectoryInfo dir = new DirectoryInfo(@"\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL
Basically, I have this code:
基本上,我有这个代码:
DirectoryInfo dir = new DirectoryInfo(@"\\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL\00806\");
FileInfo[] files = dir.GetFiles("200810*");
I expect it to match any files starting with 200810. However, it's matching files named
我希望它匹配任何以200810开头的文件。但是,它匹配的文件名为
20070618_00806.bak and 20070817_00806.bak (the stars aren't in the filename, that was the only way I could include the underscore)
20070618_00806.bak和20070817_00806.bak(星号不在文件名中,这是我可以包含下划线的唯一方法)
I tried it with dir from a command prompt, and it matches those files also. Why?
我在命令提示符下用dir尝试了它,它也匹配这些文件。为什么?
Edit:
Maybe using C: as the example was not a good thing. The directory I'm actually querying is a network share \\MYNETWORK11\ABCDEFG\ABCDEFGHIJKL\00806\
也许使用C:作为示例并不是一件好事。我实际查询的目录是网络共享\\ MYNETWORK11 \ ABCDEFG \ ABCDEFGHIJKL \ 00806 \
If checking against the short name has anything to do with it, won't 20070817_00806.bak be 200708~1.bak? That doesn't match either
如果检查短名称与它有关,20070817_00806.bak不会是200708~1.bak吗?那也不匹配
4 个解决方案
#1
msdn states that
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"."
“因为此方法使用8.3文件名格式和长文件名格式检查文件名,所以类似于”* 1 * .txt“的搜索模式可能会返回意外的文件名。例如,使用”*的搜索模式“ 1 * .txt“将返回”longfilename.txt“,因为等效的8.3文件名格式为”longf~1.txt“。”
Could this be the cause?
这可能是原因吗?
#2
Try this from the command line:
从命令行尝试这个:
dir /x 200810*
The "/x" will make it show the short filenames, as well as the long filenames. This would let you see whether the short filename actually does start with "200810".
“/ x”将使其显示短文件名以及长文件名。这将让你看看短文件名实际上是否以“200810”开头。
#3
I can't reproduce this, either from the command line or in a test app:
我无法从命令行或测试应用程序中重现这一点:
c:\Users\Jon\Test>echo > 20070618_00806.bak
c:\Users\Jon\Test>echo > 2007081700806.bak
c:\Users\Jon\Test>dir 200810*
Volume in drive C is OS
Volume Serial Number is B860-7E20
Directory of c:\Users\Jon\Test
File Not Found
And the C# app:
和C#应用程序:
using System;
using System.IO;
class Test
{
static void Main()
{
foreach (var file in new DirectoryInfo(".").GetFiles("200810*"))
{
Console.WriteLine(file);
}
}
}
(This doesn't print any results.)
(这不会打印任何结果。)
Perhaps there's some OS setting somewhere which is making a difference... which OS are you using? (I'm on 32-bit Vista.)
也许某些操作系统设置在哪里有所作为...你在使用哪种操作系统? (我在32位Vista上。)
#4
GetFiles will search the long file name and the short filename...it's not somehow matching short file names is it?
GetFiles将搜索长文件名和短文件名...它不是以某种方式匹配短文件名吗?
806\");
FileInfo[] files = dir.GetFiles("200810*");
Di