比如说我要在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;
}
- 2 回答
- 0 关注
- 289 浏览
添加回答
举报
0/150
提交
取消