Vbscript / Text Processing / Merge File Contents
Merge contents of all files within a folder to produce a single file. Useful for combining comma separated value (csv) or tab separated value (tsv) files into one data set.
Set objFSO = CreateObject("Scripting.FileSystemObject") opName = "CollatedFile.txt" Set outFile = objFSO.OpenTextFile(opName,8, True) 'Loop through input files Set srcDir = objFSO.GetFolder(".") Set files = srcDir.Files For Each file in files If objFSO.getExtensionName(file) <> "vbs" AND objFSO.getFileName(file) <> opName Then 'On Error Resume Next Set fileN = objFSO.OpenTextFile(file, 1) content = fileN.readAll outFile.Write content If Err.Number <> 0 Then Wscript.Echo Err.Description & ": " & fileN End If End If Next outFile.Close WScript.Echo "Done"
Please note that a disclaimer applies to any code on this page.
|