【发布时间】:2017-07-20 18:03:59
【问题描述】:
我有一个包含多个子目录的目录,其中包含 .doc 文件。示例:
C:\Users\user\Documents\testenviroment\Released\test0.doc
C:\Users\user\Documents\testenviroment\Debug\test1.doc
C:\Users\user\Documents1\testenviroment\Debug\test2.doc
C:\Users\user\Documents1\testenviroment\Released\test20.doc
我想获取所有 Debug 文件夹下的所有 test*.doc 文件。我试过了:
string[] files = Directory.GetFiles(@"C:\Users\user", "*Debug\\test*.doc",
SearchOption.AllDirectories);
它给了我一个“路径中的非法字符”错误。
如果我尝试:
string[] files = Directory.GetFiles(@"C:\Users\user", "\\Debug\\test*.doc",
SearchOption.AllDirectories);
我收到另一个错误:“找不到路径 C:\Users\user\Debug 的一部分”。
【问题讨论】:
-
如果路径类似于
C:\Users\user\Documents,为什么要在C:\Users\user\Debug中搜索? -
@HimBromBeere:是的,你可以。会计。到 MSDN
The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.msdn.microsoft.com/en-us/library/ms143316(v=vs.110).aspx -
你的路径中肯定有非法字符。您的搜索字符串没有任何问题/
-
我的错。是的,实际上看起来不够好。通配符是正确的,这就是使问题一见钟情的原因。
标签: c#