I need to be able to join all text files within a folder, to 1 "Master.txt". Anyone here have a soultion for me?
There will be between 20 and 100 text files, most with different titles.
Thanks ahead of time
Printable View
I need to be able to join all text files within a folder, to 1 "Master.txt". Anyone here have a soultion for me?
There will be between 20 and 100 text files, most with different titles.
Thanks ahead of time
Something like this, but you may to tune it up:
VB Code:
Public Sub CombineFiles(strPath As String, strNewFile As String) '================================================================ ' to simplify processing the following must be in order: ' - strNewFile must havefull file name including extension ' - strPath must represent full path to your folder '================================================================ Dim strFile As String Dim strLine As String Dim strExtension As String Dim FileNumber On Error GoTo ErrClear If Not Right(strPath, 1) = "\" Then strPath = strPath & "\" strExtension = LCase(Right(strNewFile, 3)) Open strPath & strNewFile For Output As #1 strFile = Dir(strPath, vbNormal) Do While strFile <> "" If strFile <> "." And strFile <> ".." Then If (GetAttr(strPath & strFile) And vbNormal) = vbNormal Then If Not strFile = strNewFile And LCase(Right(strFile, 3)) = strExtension Then FileNumber = FreeFile Open strPath & strFile For Input As #FileNumber Do Line Input #FileNumber, strLine Print #1, strLine Loop Until EOF(FileNumber) Close #FileNumber End If End If End If strFile = Dir Loop Close #1 Exit Sub ErrClear: '----------- Err.Clear Resume Next End Sub
Usage:
VB Code:
Private Sub Command1_Click() CombineFiles "c:\temp", "bigfile.txt" End Sub
You may use MS Word application to do that.
VB Code:
Dim wa As Object Set wa = CreateObject("Word.Application") With wa .Documents.Open "C:\t1.txt" .ActiveDocument.Select .Selection.EndOf For j = 2 To 4 .Selection.InsertFile "C:\t" & j & ".txt", , False, , False .Selection.EndOf Next j .Quit wdSaveChanges End With
As far as memory concern, it will be an overkill using Word, but it will get job done.