Re: combine two text files

From: '69 Camaro (ForwardZERO_SPAM.To.69Camaro_at_Spameater.orgZERO_SPAM)
Date: 12/22/04


Date: Tue, 21 Dec 2004 23:19:51 -0800

Hi.

> Is there something like
> FileCopy "this", "tothis"
>
> that I can use to concatenate two files, similar to the
> DOS command
>
> copy "this" + "andthis" "tothis"

In addition to what John Nurick suggested, you could also use a batch file.
I'd recommend using the DOS append command instead of the DOS Copy command,
because the append command doesn't append a non-viewable character at the
end of the file like the Copy command does, which would probably have to be
removed later.

Create a batch file and execute it with the Shell Command method from VBA.
To do so, open the DOS command shell and type (or paste) the following:

Copy con AppendF.BAT
Echo Off
Type %1 %2 >> %3
Echo On

To copy the text from the console to the AppendF.BAT file, type:
<CTRL>Z

DOS will return the following message:
        1 file(s) copied.

You'll need to know the directory where this file is stored so that DOS can
execute it even if it's not in the computer's environment path. For example
purposes, we'll store it in C:\Test. Create two text files and store them
in the same directory. We'll call these text files test1.txt and test2.txt.
Paste the following as a subroutine in a standard module (we'll call it
MyModule):

Public Sub ConcatFiles( )

    On Error GoTo ErrHandler

    Dim sFile As String
    Dim sFileNext As String
    Dim sFileConcat As String
    Dim sCmd As String
    Dim rtn As Double

    sFile = "C:\Test\test1.txt"
    sFileNext = "C:\Test\test2.txt"
    sFileConcat = "C:\Test\test3.txt"

    sCmd = "C:\Test\AppendF.BAT " & sFile & " " & sFileNext & " " &
sFileConcat

    rtn = Shell(sCmd, vbHide)

    If (rtn = 0) Then
        MsgBox "There was an error processing the command."
    End If

    Exit Sub

ErrHandler:

    MsgBox "Error in ConcatFiles( ) in MyModule." & vbCrLf & vbCrLf & _
        "Error #" & Err.Number & vbCrLf & Err.Description
    Err.Clear
End Sub

Now execute the sub to see how it works. The batch file you've written is
generic and will allow any two files to be concatenated into a third file.
All three file names (and their respective paths) are passed to the batch
file via the command-line arguments, each separated by a space.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

"notDave" <anonymous@discussions.microsoft.com> wrote in message
news:052001c4e79e$1820fa80$a601280a@phx.gbl...
> Is there something like
> FileCopy "this", "tothis"
>
> that I can use to concatenate two files, similar to the
> DOS command
>
> copy "this" + "andthis" "tothis"
>
> ~notDave



Relevant Pages

  • Re: Shell Functions and DOS executables
    ... I had to create a .BAT file that actually made the call to the exe, ... Dim wshExec As IWshRuntimeLibrary.wshExec ... I followed the above and the DOS command executes perfectly! ...
    (microsoft.public.vb.general.discussion)
  • Re: How to parse output from a command
    ... Dim RegEx, WSH ... Set WSH = CreateObject ... > bypass the DOS command all together, thinking there would be an easy way ...
    (microsoft.public.scripting.vbscript)
  • Re: DOS / XP bat file programming question
    ... How do I feed a "y" response to a DOS command that wants to prompt me ... Note that DOS is an operating system, same as Windows XP. ... There is no DOS under Windows, only a Command Prompt. ...
    (microsoft.public.windowsxp.general)
  • Re: Master Boot Record
    ... Is the DOS program relating to the commands which you mentioned in your ... > If you don't know why you'd want to restore or backup a boot sector then don't do it. ... It also contains the partition table. ... The LOCK command enables direct disk access by programs ...
    (microsoft.public.windowsxp.general)
  • Re: newbie: I/O with nasm
    ... A program that starts with "main" and is linked with gcc has the "_start" label in the C startup code, and the stack is slightly different when we get control at "main". ... Dos is *very* different, as you point out. ... Working on up the (Linux) stack, the list of command line argument pointers is terminated with a zero. ...
    (alt.lang.asm)