Solved

Concatenate Files

Posted on 2000-05-11
6
1,078 Views
Last Modified: 2011-04-14
I would like to concatenate two files like in the DOS command:

copy a.txt+b.txt,c.txt

How can this be done in VB without parsing the files?

Best regards,
Sorin
0
Comment
Question by:axasb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2801412
Private Sub JoinFile(File1, File2, NFile)
    Dim Buffer() As Byte
    Open File1 For Binary Access Read As #1
    Open File2 For Binary Access Read As #2
    Open NFile For Binary Access Write As #3
    ReDim Buffer(1 To LOF(1))
    Get #1, , Buffer
    Put #3, , Buffer
    ReDim Buffer(1 To LOF(2))
    Get #2, , Buffer
    Put #3, , Buffer
    Close #1, #2, #3
End Sub

Private Sub Command1_Click()
    Call JoinFile("c:\files\1.txt", "c:\files\2.txt", _
        "c:\files\3.txt")
End Sub
0
 

Author Comment

by:axasb
ID: 2801442
Thank you AzraSound.
You are very quick.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 2801479
- submitting answer -

Youre welcome  =)
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 12

Expert Comment

by:mark2150
ID: 2801529
you could also do it the DOS way with SHELL...

M
0
 
LVL 28

Expert Comment

by:Ark
ID: 2802592
Hi
To join ANY number of files (like in DOS):
Private Function ConCatFiles(sDest As String, ParamArray _
   sInputFiles()) As Boolean
   

  Dim bTemp() As Byte, nDestFile As Integer
  Dim nSrcFile As Integer, i As Integer
  On Error GoTo ErrHandler
  ReDim sTemp(UBound(sInputFiles()))
  nDestFile = FreeFile
  Open sDest For Binary Access Write As nDestFile
  For i = 0 To UBound(sInputFiles)
      nSrcFile = FreeFile
      Open sInputFiles(i) For Binary Access Read As nSrcFile
      ReDim bTemp(LOF(nSrcFile) - 1)
      Get nSrcFile, , bTemp
      Put nDestFile, , bTemp
      Close nSrcFile
  Next i
  Close nDestFile
  On Error GoTo 0
  ConCatFiles = True
 
  Exit Function
ErrHandler:
  'OPTIONAL, OR CALLER CAN JUST CHECK RETURN VALUE
  'MsgBox "Unable to concatenate files.", vbCritical
  On Error GoTo 0
  Close
End Function

'Using
'Private Sub Command1_Click()
'ConCatFiles "c:\temp.txt", "c:\autoexec.bat", "c:\config.sys", "c:\msdos.sys"
'End Sub
'Result - output file "c:\temp.txt" is a sum of all three source files

Cheers
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2804138
Shell "C:\command.com /b copy a.txt+b.txt,c.txt"

M
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month6 days, 16 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question