|
-
Nov 22nd, 2002, 01:40 PM
#1
Thread Starter
Lively Member
Folder full of .txt's to 1 .txt
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
-
Nov 22nd, 2002, 01:53 PM
#2
PowerPoster
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
-
Nov 22nd, 2002, 01:54 PM
#3
PowerPoster
Usage:
VB Code:
Private Sub Command1_Click()
CombineFiles "c:\temp", "bigfile.txt"
End Sub
-
Nov 22nd, 2002, 02:08 PM
#4
Frenzied Member
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
-
Nov 23rd, 2002, 08:38 AM
#5
PowerPoster
As far as memory concern, it will be an overkill using Word, but it will get job done.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|