Combining two files (Copy file1.txt + file2.txt) 
Author Message
 Combining two files (Copy file1.txt + file2.txt)

I desperately need a command to copy two files together.  In DOS, this was
easy.  For example, to attach file2.txt to the end of file1.txt and store it
as file3.txt, you would use
copy file1.txt + file2.txt file3.txt

What VB or Windows API calls can I use to achieve this?  I've tried doing
this by simply reading in each of the two files and combining them manually.
This is extremely slow, however.  Any tips?

Thanks,
Russell Davis
---



Tue, 04 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

Try using byte arrays to read/write the files and open all files involved As
Binary.



Tue, 04 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

Try

'Open Two Input Files
    Open File1$ for Binary as #1
    Open File2$ for Binary as #2

'Open Output File
    Open NewFile3$ For Binary as #3

'Get File 1, then write to new file
    Buffer$=Space$(LOF(1))
    Get #1, Buffer$
    Put #3, Buffer$

'Get File 2, then write to new file
    Buffer$=Space$(LOF(2))
    Get #2, Buffer$
    Put #3, Buffer$

'Close
    Close #1
    Close #2
    Close #3

There are other ways, but this one is simple to use and understand. As
UniCode becomes more common (or in some foreign versions of VB?) this method
may not work. You could use a Byte array instead of strings, but the strings
will work for what I think you are doing.

Greg



Tue, 04 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

Is there any speed difference using a byte array?

        Dim FileData() As Byte
        Dim FileLength as Long

        Open File1$ for Binary as #1
        Open File2$ for Binary as #2
        Open NewFile3$ For Binary as #3

        ReDim FileData(0 To LOF(1) - 1)
        Get #1, FileData()
        Put #3, FileData()
        FileLength = LOF(3)

        ReDim FileData(0 To LOF(2) - 1)
        Get #2, Buffer$
        Put #3,FileLength + 1, Buffer$

        Close #1
        Close #2
        Close #3

-- Dustin



Tue, 04 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

I wouldn't think so. I prefer byte arrays myself. The example I used was
with strings, because it was easier for newbies to understand.

Greg



Tue, 04 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

It works using this method (I already knew how to do that).  It just seems
like its being innefecient to load the whole file into memory, only to write
it back to disk.  Is there some way to do it directly, so it could just take
the copy the files together straight from the disk?  I am combining large
files, so I need it to be as fast as possible.  Any other suggestions are
gladly welcomed!

Thanks,
Russell Davis

Quote:

>Try

>'Open Two Input Files
>    Open File1$ for Binary as #1
>    Open File2$ for Binary as #2

>'Open Output File
>    Open NewFile3$ For Binary as #3

>'Get File 1, then write to new file
>    Buffer$=Space$(LOF(1))
>    Get #1, Buffer$
>    Put #3, Buffer$

>'Get File 2, then write to new file
>    Buffer$=Space$(LOF(2))
>    Get #2, Buffer$
>    Put #3, Buffer$

>'Close
>    Close #1
>    Close #2
>    Close #3

>There are other ways, but this one is simple to use and understand. As
>UniCode becomes more common (or in some foreign versions of VB?) this
method
>may not work. You could use a Byte array instead of strings, but the
strings
>will work for what I think you are doing.

>Greg




Tue, 04 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

Well, in C++, you can open a file and make it appear to be a memory block.
Using a similair techique as described before, you could write the file
without loading it into memory.

If you want to stay fully VB, another way is using the method before, but
limited the buffer size to a set size and looping the file. This will not
require the entire large file to be loaded in memory, but will take slightly
longer.

Greg



Wed, 05 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

With simple string variable work:

Dim s As String

'Open Two Input Files
    Open File1$ for Binary as #1
    Open File2$ for Binary as #2

'Open Output File
    Open NewFile3$ For Binary as #3

'Get File 1, then write to new file
    s = Imput$(Lof(1), 1)
    Put #3, , s

'Get File 2, then write to new file
    s = Imput$(Lof(2), 2)
    Put #3, , s

'Close
    Close 1, 2, 3

PS. Care with Put and Get sintax is
Put #Channel, , s
Not
Put #Channel, s
--
***********************************************
Visual Experto:
   http://www.geocities.com/SiliconValley/Horizon/5305/

Por favor registra tu vista desde el vinculo "Registro de Visita"
************************************************



Wed, 05 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

An Idea...

What if you used:

 Put #3, , Input$(Lof(1), 1)

This might just be the quickest way.

Greg


Quote:
>With simple string variable work:

>Dim s As String

>'Open Two Input Files
>    Open File1$ for Binary as #1
>    Open File2$ for Binary as #2

>'Open Output File
>    Open NewFile3$ For Binary as #3

>'Get File 1, then write to new file
>    s = Imput$(Lof(1), 1)
>    Put #3, , s

>'Get File 2, then write to new file
>    s = Imput$(Lof(2), 2)
>    Put #3, , s

>'Close
>    Close 1, 2, 3

>PS. Care with Put and Get sintax is
>Put #Channel, , s
>Not
>Put #Channel, s
>--
>***********************************************
>Visual Experto:
>   http://www.geocities.com/SiliconValley/Horizon/5305/

>Por favor registra tu vista desde el vinculo "Registro de Visita"
>************************************************



Wed, 05 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

It might not necessarily take longer.  If you're reading a really large file
into memory all at once, Windows may have to swap to disk... so you'd
actually be reading from disk, writing to disk (virtual memory), reading
back from disk (virtual memory), then writing to disk again.

It really depends on the size of the file, the amount of memory available on
the system, other applications that are running, etc.

In some cases, looping might actually be faster.

--
Matthew A. Feinberg

ICQ: 3494579

Quote:

>Well, in C++, you can open a file and make it appear to be a memory block.
>Using a similair techique as described before, you could write the file
>without loading it into memory.

>If you want to stay fully VB, another way is using the method before, but
>limited the buffer size to a set size and looping the file. This will not
>require the entire large file to be loaded in memory, but will take
slightly
>longer.

>Greg



Wed, 05 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

G>
What if you used:

 Put #3, , Input$(Lof(1), 1)

This might just be the quickest way.
H>
No, no, no
This is not correct.
Binary write It requires a variable -not an expression  
--
***********************************************
Visual Experto:
   http://www.geocities.com/SiliconValley/Horizon/5305/

************************************************



Wed, 05 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

On Fri, 16 Jan 1998 15:25:21 -0800, "Russell Davis"

Quote:

>I desperately need a command to copy two files together.  In DOS, this was
>easy.  For example, to attach file2.txt to the end of file1.txt and store it
>as file3.txt, you would use
>copy file1.txt + file2.txt file3.txt

>What VB or Windows API calls can I use to achieve this?  I've tried doing
>this by simply reading in each of the two files and combining them manually.
>This is extremely slow, however.  Any tips?

>Thanks,
>Russell Davis
>---


Just a thought, how about making a copy of the first file, then open
the copy for append, and write the second file onto the end of the
copy in the usual way.

Alternatively, a bit of a cop out, but you could always create a batch
file on the fly to do:  copy file1.txt + file2.txt file3.txt and run
it hidden.

Regards Dave.



Thu, 06 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

I do not know if this has been tried or said but how about copying the first
file to the new file name and then opening it for append assuming it is a
plain text file. Then adding the contents of file 2.  Saves opening 3 files
plus storage of file contents.  Just a thought.

Robbie

Quote:

>It might not necessarily take longer.  If you're reading a really large
file
>into memory all at once, Windows may have to swap to disk... so you'd
>actually be reading from disk, writing to disk (virtual memory), reading
>back from disk (virtual memory), then writing to disk again.

>It really depends on the size of the file, the amount of memory available
on
>the system, other applications that are running, etc.

>In some cases, looping might actually be faster.

>--
>Matthew A. Feinberg

>ICQ: 3494579


>>Well, in C++, you can open a file and make it appear to be a memory block.
>>Using a similair techique as described before, you could write the file
>>without loading it into memory.

>>If you want to stay fully VB, another way is using the method before, but
>>limited the buffer size to a set size and looping the file. This will not
>>require the entire large file to be loaded in memory, but will take
>slightly
>>longer.

>>Greg



Thu, 06 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

Sorry that was for Windows NT try Command /c for Windows 95...

Thanks David L. Gorman
AutoMation Programmer/Programmer
CompuCOM Systems Incorp.
1-609-224-5149



Quote:
> I desperately need a command to copy two files together.  In DOS, this
was
> easy.  For example, to attach file2.txt to the end of file1.txt and store
it
> as file3.txt, you would use
> copy file1.txt + file2.txt file3.txt

> What VB or Windows API calls can I use to achieve this?  I've tried doing
> this by simply reading in each of the two files and combining them
manually.
> This is extremely slow, however.  Any tips?

> Thanks,
> Russell Davis
> ---




Fri, 07 Jul 2000 03:00:00 GMT  
 Combining two files (Copy file1.txt + file2.txt)

Private Sub Form_Load()
   Dim FileName1 As String
   Dim FileName2 As String
   Dim Merged_FileName As String
   Dim ShellFile As String
   Dim ShellCheck As Integer

   FileName1 = "C:\File1.txt"
   FileName2 = "C:\File2.txt"
   Merged_FileName = "C:\File.txt"

   ShellFile = "cmd /c" + Chr$(34) + "copy " + FileName1 + " + " +
FileName2 + _
            " " + Merged_FileName
   ShellCheck = Shell(ShellFile, vbHide)
End Sub

Thanks David L. Gorman
AutoMation Programmer/Programmer
CompuCOM Systems Incorp.
1-609-224-5149



Quote:
> I desperately need a command to copy two files together.  In DOS, this
was
> easy.  For example, to attach file2.txt to the end of file1.txt and store
it
> as file3.txt, you would use
> copy file1.txt + file2.txt file3.txt

> What VB or Windows API calls can I use to achieve this?  I've tried doing
> this by simply reading in each of the two files and combining them
manually.
> This is extremely slow, however.  Any tips?

> Thanks,
> Russell Davis
> ---




Fri, 07 Jul 2000 03:00:00 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Combining two files (Copy file1.txt + file2.txt)

2. question on "shell copy file1.txt+file2.txt"

3. Need a vbCopy similar to MS-DOS's COPY /B FILE1 + FILE2 NEWFILE

4. Adding .TXT files to a VB program without the .TXT file

5. How to copy txt-file to module with VB

6. Copying large txt files together?!

7. Stupid "Name file1 As file2" problem

8. copying from txt files

9. Append File2 to File1...

10. Copying All *.txt Files

11. txt to txt

12. ODBC API calls from VB4.0 Professional Edition - ODBC16.TXT and ODBC32.TXT

 

 
Powered by phpBB® Forum Software