Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to concatenate files together in vbscript

Status
Not open for further replies.

chickety

Programmer
Dec 11, 2002
3
US
I need to be able to concatenate the content of all files in a specific folder into one file. Is there an easy way to do this in vbscript? Should I open each file using OpenTextFile and then append the contents of it to a TextStreamObject? After looping through all files, then write the file out from the TextStreamObject?

Am I going down the right path or is there an easier way to do this?

Does anyone have any vbscript code that does this already?
 
this works for me


Set ss = CreateObject("WScript.Shell")
ss.run "command /c copy c:\folder\*.* c:\folder\all.dat",1,true
set ss = nothing

In windows 2000 the command /c would be cmd /c
Enjoy Bob
 
You may have little choice but to run a command to do this. The FSO only deals with text files, there is no way to read in some arbitrary chunk of data then write it, only read in the whole file or a "line" - and binary files will likely catch you sooner or later, plus you risk distorting the data.

If your data files are ALL just text that method can work too of course, it'll be a little slower though.

The other possibility is to create your own ActiveX component in VB or something, then invoke that from script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top