Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Merge File Contents
 

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.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
          - Filter Text Lines Containing
          - Get Html Tag Content
          - Merge File Contents
          - Read Xml File
     - User Interaction
     - Web Servers