您的位置:首页 > 编程语言 > ASP

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

2015-05-09 15:10 309 查看
 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");  //自动寻找目录、

                }

            }

        }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐