Re: Appending text files
From: Björn Holmgren (bjohol_at_hotmail.com)
Date: 06/09/04
- Next message: Gale Green: "Re: Outlook 2000"
- Previous message: MikeD: "Re: Timers and DoEvents"
- In reply to: softrock: "Appending text files"
- Next in thread: Rick Rothstein: "Re: Appending text files"
- Reply: Rick Rothstein: "Re: Appending text files"
- Reply: softrock: "Re: Appending text files"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Jun 2004 15:32:28 +0200
"softrock" <anonymous@discussions.microsoft.com> wrote in message
news:62E81C85-DBAC-4685-8548-20F6FD0D3F32@microsoft.com...
> Does anyone know how to append text files using VB? I am outputting three
text files from SQL Server using DTS. The first file contains header data,
the second contains the base data and the third contains trailer data. I
need to be able to append the header data at the beginning of the base data
and the trailed data on the end. I've never appended text files before and
would really appreciate some help. I am using VB6 and SQL Server 2000 on an
NT4 box.
Here's one way:
When you call the JoinFiles subroutine you must pass it an array of files to
join. The array can contain one or more filenames. You also pass it the name
of an output file which will receive the joined contents.
Example:
Call JoinFiles(Array("File1.txt", "File2.txt", "File3.txt"), "File123.txt")
(joins File1.txt, File2.txt and File3.txt, outputs result to File123.txt)
'----------
' Joins two or more files
' Note: First parameter expected to be an array of filenames
Sub JoinFiles(sFiles As Variant, sFileNew As String)
Dim Index As Long
Dim FileIn As Long
Dim FileOut As Long
Dim sBuf As String
' Create the new output file
FileOut = FreeFile
Open sFileNew For Binary Access Write As #FileOut
' For each file in the sFiles array...
For Index = LBound(sFiles) To UBound(sFiles)
' Open the input file
FileIn = FreeFile
Open sFiles(Index) For Binary Access Read As FileIn
' Create a string buffer to hold the entire file contents
sBuf = Space(FileLen(sFiles(Index)))
' Read the contents of the file to the string buffer
Get #FileIn, , sBuf
' Close the input file
Close #FileIn
' Write the string buffer to the output file
Put #FileOut, , sBuf
Next
' Close the output file
Close #FileOut
End Sub
'----------
-- Björn Holmgren Guide Konsult AB
- Next message: Gale Green: "Re: Outlook 2000"
- Previous message: MikeD: "Re: Timers and DoEvents"
- In reply to: softrock: "Appending text files"
- Next in thread: Rick Rothstein: "Re: Appending text files"
- Reply: Rick Rothstein: "Re: Appending text files"
- Reply: softrock: "Re: Appending text files"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|