判断是否下载指定客户端(遍历硬盘上的全部文件文件夹)

来源:互联网 发布:淘宝创想电玩 编辑:程序博客网 时间:2024/06/06 03:36
 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 Button1_Click(object sender, EventArgs e)
    {
        DriveInfo[] allDrives = DriveInfo.GetDrives();
      

        for (int i = allDrives.Length - 1; i >= 0; i--)
        {
            if (allDrives[i].Name != "C:\\")
            {

                if (allDrives[i].DriveType.ToString() == "Fixed")
                {

                    GetAllFiles(allDrives[i].Name, "exe");  //自动寻找目录、
                }
            }
        }
    }

0 0