Appending Text from one text file to another

V

vqthomf

Hi can anyone help I am trying to select all records from a text file ane
append the text into another text file.
 
K

Karl E. Peterson

vqthomf said:
Hi can anyone help I am trying to select all records from a text file ane
append the text into another text file.

Call WriteFile("f1.txt", ReadFile("f1.txt") & ReadFile("f2.txt"))

Public Function ReadFile(ByVal FileName As String) As String
Dim hFile As Long
On Error GoTo Hell
hFile = FreeFile
Open FileName For Binary As #hFile
ReadFile = Space$(LOF(hFile))
Get #hFile, , ReadFile
Close #hFile
Hell:
End Function

Public Function WriteFile(ByVal FileName As String, ByVal Text As String) As
Boolean
Dim hFile As Long
On Error GoTo Hell
hFile = FreeFile
Open FileName For Output As #hFile
Print #hFile, Text
Close #hFile
Hell:
WriteFile = Not CBool(Err.Number)
End Function

If your files are humongous (in the >100Mb range), more optimal solutions are
available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top