List<string> myList = new List<string>();
// 執行檔路徑下的 MyDir 資料夾
string folderName = System.Windows.Forms.Application.StartupPath + @"\MyDir";
// 取得資料夾內所有檔案
foreach (string fname in System.IO.Directory.GetFiles(folderName))
{
string line;
// 一次讀取一行
System.IO.StreamReader file = new System.IO.StreamReader(fname);
while ((line = file.ReadLine()) != null)
{
myList.Add(line.Trim());
}
file.Close();
}
參考:
Directory 方法
程式碼:一次一行讀取文字檔 (Visual C#)
.NET 4.0 New Feature - 遍尋檔案系統項目與檔案內容的效能強化
沒有留言:
張貼留言