天天看點

C# 打開檔案目錄并讀取整個目錄資訊

private void openProject_Click(object sender, EventArgs e)
        {
            //打開目錄對話框
            string strfolderPath = "";
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            if (folderDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)

                strfolderPath = folderDialog.SelectedPath;
            //截取所有檔案位址資訊
            if (strfolderPath.Length > 0)
            {
                string[] htmlFiles = Directory.GetFiles(strfolderPath, "*.html", SearchOption.AllDirectories);
                fileList.BringToFront();
                fileList.Items.AddRange(htmlFiles);
                this.Controls.Add(fileList);

                for (int i = 0; i < fileList.Items.Count; i++)
                {
                    string filePathName = fileList.Items[i].ToString();
                    //讀取單個檔案
                    ReadFile(filePathName);

                }
                MessageBox.Show("檔案檢查完畢,檢查結果檔案存放在e:\\Errorfile.txt");

            }
           
        }