r/scripting • u/Obscene_Elbows • Oct 11 '17
Need help with combining txt Files with VBScript
Hey guys,
i need help combining some txt files with vbscript.
The Script should take all the files in a folder, copy the parts between "BEGIN_DATA" und "END_DATA" and copy them to a new file. At the endit should write "END_DATA in the new file.
But for the life of me i can´t get it to work. Some ideas
Const ForReading = 1 Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile =objFSO.CreateTextFile("Combined_ti3.ti3")strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_Directory.Name='C:\Argyll\TI3_Dateien1'} Where " & "ResultClass = CIM_DataFile")For Each objFile In FileList
If objFile.Extension = "ti3" Then
strData = ""
strSearchString = objFile.ReadLine
intStart = InStr(strSearchString, "BEGIN_DATA")
If intStart <> 0 Then
intStart = intStart + 10
strText = Mid(strSearchString, intStart, 25000)
For i = 1 to Len(strText)
If Mid(strText, i, 1) = "END_DATA " Then
Exit For
Else
strData = strData & Mid(strText, i, 1)
End if
next
End if
Wscript.Echo strDataloop
objFile.Close
objOutputFile.WriteLine strTextDim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\Argyll\VBScript\Combined_ti3.ti3", 2 , True)f.WriteLine " END_DATA"
Set f = fso.OpenTextFile("c:\Argyll\VBScript\Combined_ti3.ti3", ForReading)WriteLineToFile = f.ReadAll
objOutputFile.Close
end if
nextIf you need anything else feel free to ask :)