Re: [.NET] 如何讀取多個文字檔呢?
※ 引述《rocksan (Rocksan)》之銘言:
: ※ 引述《mohocho (去你的火星人)》之銘言:
: : 日前寫了個小小程式
: : 把兩個文字檔中的字串抓出來做比較
: : Dim str1 As StreamReader = File.OpenText("D:\1.txt")
: : Dim str2 As StreamReader = File.OpenText("D:\2.txt")
: : TextBox1.Text = str1.ReadToEnd()
: : TextBox2.Text = str2.ReadToEnd()
: : If TextBox1.Text = TextBox2.Text Then
: : Label1.Text = 1
: : Else
: : Label1.Text = 0
: : End If
: : 現在我想把他擴充成讀取多個但不定數量檔然後跟某檔比較
: : 就是說把全部文字檔都讀進來
: : 然後以其中一個為標準 剩下的每個都跟他比較
: : 不過問題是我之前小小版是把檔名寫死在裡面
: : 現在要抓的檔檔名跟數量都不是固定
: : 這樣要怎麼處理呢??
: =======================================
: 這個程式,主要的功能為將指定的資料夾中所有的文字檔,全部讀取進來並且
: 跟某個文字檔比較內容,並把相同,與不相同的檔名記錄下來。
: 這是我目前的想法,說不定有更好的做法唷。
: 小弟也是VB.NET新手,多多互相討論
: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
: System.EventArgs) Handles Button1.Click
: Dim stritem As String
: Dim Filelist As New ArrayList
: Dim Samelist As New ArrayList
: Dim Difflist As New ArrayList
: Dim str1 As StreamReader
: Dim str2 As StreamReader
: ChDir("c:\")
: '改變目前的資料夾
: stritem = Dir("*.txt")
: '找出目前資料夾中所有副檔名為txt的檔案名稱
: Do Until stritem = ""
: Filelist.Add(stritem)
: '記錄所有的檔案路徑
: stritem = Dir()
: ' 下一個
: Loop
: str1 = File.OpenText("c:\01.txt")
: TextBox1.Text = str1.ReadToEnd
: '用來做為比較的文字檔
: For i As Integer = 1 To Filelist.Count - 1
: str2 = File.OpenText((CStr(Filelist.Item(i))))
: '讀進所有的文字檔,一一比較
: TextBox2.Text = str2.ReadToEnd
: If TextBox1.Text = TextBox2.Text Then
: Samelist.Add(CStr(Filelist.Item(i)))
: '記錄內容相同的檔名
: Else
: Difflist.Add(CStr(Filelist.Item(i)))
: '記錄內容不相同的檔名
: End If
: Next
: ListBox1.DataSource = Samelist
: ListBox2.DataSource = Difflist
: '在LISTBOX中顯示出來
: End Sub
可以繼續問嗎?[vb6]
如果要讓使用者選取多個檔案
然後先把這些檔名記下來
再一一對他們操作
目前只知道怎麼開啟一個檔案...
With CommonDialog1
.InitDir = App.Path
' add excel files
.Filter = "Text Files, Excel(CSV) Files|*.txt;*.csv"
.Action = 1
End With
CommonDialog有property
可以同時選取多個檔案嗎
那檔名格式的存取方式是什麼x
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.66.84.2
※ 編輯: slasher 來自: 203.66.84.2 (07/06 16:40)
※ 編輯: slasher 來自: 203.66.84.2 (07/06 17:52)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章