The code below works perfectly, what it does is read each line of a file, then copies the entire contents of that file to another file. The idea of the program is to combine 500 or so files i have it at work into one big long file.
The purpose of this post, is to ask if theres a better way of doing his, rather than streamreader within the for loop, as i dont like having declarations mid-way through some code.
Thanks.
The purpose of this post, is to ask if theres a better way of doing his, rather than streamreader within the for loop, as i dont like having declarations mid-way through some code.
Code:
sets up to write to a file
Dim path As String = txtFolder.Text
Dim strTextToFile As New System.IO.StreamWriter(txtFolder.Text + "\tbls.txt", False)
Dim strNewFile As String
sets up to read list of files
Dim sr As StreamReader = New StreamReader(txtFolder.Text + "\tblslist.txt")
Do While sr.Peek() >= 0
MsgBox(sr.ReadLine)
opens the reader for each file
Dim reader As New System.IO.StreamReader(sr.ReadLine())
Dim textfromfile As String = reader.ReadToEnd()
Adds the files up to one big one
strNewFile = strNewFile & textfromfile & Chr(13)
reader.Close()
Loop
sr.Close()
writes to file and closes
strTextToFile.WriteLine(strNewFile)
strTextToFile.Close()
MsgBox("Document Finished!", MsgBoxStyle.Information)
Thanks.