Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

How can I append a text file to another text file?

I would like to append a text file to another text file.
They should be appended by order of date and time, with the data for the most recent to be on the top.
Avatar of jkaios
jkaios
Flag of Marshall Islands image

Sub appendFile()

   Dim WshShell As Object
   Set WshShell = CreateObject("WScript.Shell")
   WshShell.Run "cmd /C type C:\Test\testfile.txt >> C:\Test\testfile2.txt"

End Sub
Or to make the sub routine more flexible:

Sub appendFile(byval strSourceFile, byval strTargetFile)

   Dim WshShell 'As Object   ------- comment out the "AS OBJECT" if runing this code from a VB script
   Set WshShell = CreateObject("WScript.Shell")
   WshShell.Run "cmd /C type " & strSourceFile & " >> " & strTargetFile

End Sub

Open in new window

Avatar of Bill Prew
Bill Prew

Not sure exactly what you are after.  Are there just 2 files involved, or are there multiple files to be added to the end of a given base file?  Need more details...

Does this have to be VBS or would BAT also work?

~bp
ASKER CERTIFIED SOLUTION
Avatar of jkaios
jkaios
Flag of Marshall Islands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of E=mc2

ASKER

Thanks.  Unsure if this works, however I will try it when possible.