停止 Directory.GetFiles() 中的隐式通配符
string[] fileEntries = Directory.GetFiles(pathName, "*.xml");
还返回诸如 foo.xml_ 之类的文件 有没有办法强制它不这样做,或者我必须编写代码来过滤返回结果。
这与命令提示符下的 dir *.xml
行为相同,但与在 Windows 资源管理器中搜索 *.xml
不同。
string[] fileEntries = Directory.GetFiles(pathName, "*.xml");
Also returns files like foo.xml_
Is there a way to force it to not do so, or will I have to write code to filter the return results.
This is the same behavior as dir *.xml
on the command prompt, but different than searching for *.xml
in windows explorer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此行为是设计使然。来自 MSDN (查看注释部分和给出的示例):
您可以按如下方式限制它:
C# 2.0:
C# 3.0:
This behavior is by design. From MSDN (look at the note section and examples given):
You could limit it as follows:
C# 2.0:
C# 3.0:
这是由于windows 8.3的搜索方法造成的。如果您尝试搜索“*.xm”,您将得到 0 个结果。
你可以在.net 2.0中使用它:
it's due to the 8.3 search method of windows. If you try to search for "*.xm" you'll get 0 results.
you can use this in .net 2.0: