为了账号安全,请及时绑定邮箱和手机立即绑定

C#如何搜索文件?

C#如何搜索文件?

C#
精慕HU 2019-02-08 11:07:27
比如说我要在F盘里查找一个叫 xxx.exe 的文件,如果找到了这个文件,则返回该文件的完整路径;若不存在该文件,则提示“不存在该文件!” 请高手给出上面功能的代码,谢谢!
查看完整描述

2 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

static String FindFile(String filename, String path)
{
if (Directory.Exists(path))
{
if (File.Exists(path + filename))
return path + filename;
String[] directorys = Directory.GetDirectories(path);
foreach (String d in directorys)
{
String p = FindFile(filename, d);
if (p != null)
return p;
}
}
return null;
}



查看完整回答
反对 回复 2019-03-01
  • 2 回答
  • 0 关注
  • 289 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信