Solved

Concatenate Files

Posted on 2000-05-11
6
1,071 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
6 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
Comment Utility
Thank you AzraSound.
You are very quick.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
Comment Utility
- submitting answer -

Youre welcome  =)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Expert Comment

by:mark2150
Comment Utility
you could also do it the DOS way with SHELL...

M
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
Shell "C:\command.com /b copy a.txt+b.txt,c.txt"

M
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now