Avatar of E=mc2
E=mc2
Flag 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.
VB Script

Avatar of undefined
Last Comment
E=mc2

8/22/2022 - Mon
jkaios

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
jkaios

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

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
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
jkaios

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
E=mc2

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