Solved

Concatenate Files

Posted on 2000-05-11
6
1,077 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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