public void GetAllFiles(string fpath, string filetype)
{
//System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(fpath); // 遍历指定文件类型的文件
//System.IO.FileInfo[] fs = dir.GetFiles("*" + filetype);
//foreach (System.IO.FileInfo f in fs)
//{
// if (f.Name == "Client.exe")
// {
// res = true;
// finame = f.FullName;
// Label1.Text = finame;
// }
//}
foreach (string f in Directory.GetDirectories(fpath)) // 遍历指定文件夹类型的文件夹
{
DirectoryInfo di = new DirectoryInfo(@f);
if (!IsSystemHidden(di))
{
if (f.IndexOf("Documents and Settings") < 0)
{
if (f.IndexOf("英雄联盟") > 0)
{
string file1 = (f + "\\TCLS\\BackgroundDownloader.exe");
string file2 = (f + "\\TCLS\\Client.exe");
if (File.Exists(file1) && File.Exists(file2))
{
Label1.Text = file2;
}
}
else
{
GetAllFiles(f, filetype);
}
}
}
}
}
private bool IsSystemHidden(DirectoryInfo dirInfo)
{
if (dirInfo.Parent == null)
{
return false;
}
string attributes = dirInfo.Attributes.ToString();
if (attributes.IndexOf("Hidden") > -1 && attributes.IndexOf("System") > -1)
{
return true;
}
return false;
}
protected void Button2_Click(object sender, EventArgs e)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo item in allDrives)
{
GetAllFiles(item.Name, "exe");
}
}