Group,
I can't seem to append multiple files into one text file. Unfortunately it's creating the first file but is not creating or appending the additional files into the first file. My code looks like this:
getRestranName = System.IO.Directory.GetFiles(folderName)
Dim counter As Integer = My.Computer.FileSystem.GetFiles(folderName).Count
fileCount = Convert.ToInt32(counter)
fileCount = fileCount - 1
hotelFolder = CStr(getFolderNameGD("O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels", propertyNo2 & "*"))
' Begin by setting the loop to read each file in folder
For i = 0 To fileCount
fileName = ""
Dim objReader1 As New System.IO.StreamReader(getRestranName(i))
fileName = getRestranName(i)
If System.IO.File.Exists(fileName) Then
Do While objReader1.Peek() <> -1
txtLine = objReader1.ReadLine()
programName = Trim(Microsoft.VisualBasic.Left(txtLine, 14))
If lineNo = 3 And programName = "(res.restran)" Then
restranSave = "C:\Restran Conversion\Restran\" & propertyNo & "restran.txt"
If i = 0 Then 'This reads the first file in the folder.
lblProgName.Text = "Copying " & fileName & "......"
System.IO.File.Copy(fileName, restranSave, True)
objReader1.Dispose()
objReader1.Close()
lblProgName.Text = "Saved temp file " & restranSave & "......"
System.IO.File.Delete(fileName)
Else 'This should read any the second through the last file and append to the first (called "restranSave")
System.IO.File.AppendAllText(restranSave, fileName)
objReader1.Dispose()
objReader1.Close()
System.IO.File.Delete(fileName)
End If
End If
lineNo = lineNo + 1
If lineNo = 4 Or lineNo > 4 Then
lineNo = 1
Exit Do
End If
Loop 'Loop to read the next line of the "i" file
End If
Next i 'Takes you to the next file in the same folder
End If
Does it appear I'm missing something? The first file gets read and copied to "restranSave". But the second, third (and so on) are not getting appended to "restranSave". Help!
As always, thanks for your assistance.
Don