如何使用c#查找文件 [英] how do I find a file with using c#

查看:223
本文介绍了如何使用c#查找文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想编写一个程序来查找c中的文件。








I want to write a program to find a file in c#



if (File.Exists(textBox1.Text))
           {

               MessageBox.Show(textBox1.Text + "was found in your system");

           }

推荐答案

不完全确定你要问的是什么......不过,如果要在特定目录中查找文件,请使用:

Not exactly sure what you are attempting to ask... However, if you want to find a file in a particular directory use this:
var myFiles = Directory.GetFiles(@"c:\some\directory\");
// OR
// Find all CS files in the directory
myFiles = Directory.GetFiles(@"c:\some\directory\", "*.cs");







参考:

http://msdn.microsoft.com/en-us /library/ms143316(v=vs.110).aspx [ ^ ]


试试这个:



Try this:

var allFiles = Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories);


这篇关于如何使用c#查找文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆