Home » KBArticles » VBSCRIPT to merge multiple text files

VBSCRIPT to merge multiple text files

Const ForReading = 1

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objOutputFile = objFSO.CreateTextFile(“output.txt”)

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2”)

Set FileList = objWMIService.ExecQuery _
(“ASSOCIATORS OF {Win32_Directory.Name=’c:temp’} Where ” _
& “ResultClass = CIM_DataFile”)

For Each objFile In FileList
Set objTextFile = objFSO.OpenTextFile(objFile.Name, ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText
Next

objOutputFile.Close

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.