Hi
How can I combine multiple *.txt files in a specific directory into one txt file in another directory using VB.NET? (And to delete blank lines at the end of the new file)
Would appreciate some help.
I know how to do it in vbscript:
How can I combine multiple *.txt files in a specific directory into one txt file in another directory using VB.NET? (And to delete blank lines at the end of the new file)
Would appreciate some help.
I know how to do it in vbscript:
VB.NET:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\logs\import\output.txt")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\scripts1'} 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
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\logs\import\output.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\logs\import\output.txt", ForWriting)
objFile.Write strNewContents
objFile.Close
MsgBox "Done!"
Last edited: