Append the Contents of Fixed Width Text File to another Fixed Width Text File (1 Viewer)

JohnLee

Registered User.
Local time
Today, 08:59
Joined
Mar 8, 2007
Messages
692
Good morning folks,

just looking for a little help with working out code to append the contents of one fixed width text file to another fixed width text file, both files will have the exact same fixed width specifications.

The reason for doing this is combine the contents of two files that are output from a scanning system into one file should both files exist for onward transmission.

I have the following code which is missing the bit I need to append the contents of one text file to the other if both exist:

Code:
[SIZE=3][FONT=Times New Roman][COLOR=green][COLOR=green]   'Checks to see if the retMail.txt file exists, if it does then[/COLOR][/COLOR][/FONT][/SIZE][COLOR=green]
[SIZE=3][FONT=Times New Roman][COLOR=blue]If[/COLOR][COLOR=#000000] FS.FileExists("B:\rtmail\rtmail.txt") = [/COLOR][COLOR=blue]True Then[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=blue]           If [/COLOR][COLOR=#000000]FS.FileExists(“B:\rtmail.fof\rtmail.txt”) =[/COLOR][COLOR=blue] True Then[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman][COLOR=red]Code to append contents of rtmail.txt file in rtmail folder to contents of rtmail.txt file in rtmail.fof folder[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=blue]Else[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=green]       'Copy the Return Mail text file to the new Folder[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=#000000]       FS.CopyFile "B:\rtmail\rtmail.txt", "B:\remail.fof\rtmail.txt"[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=green]‘Delete the rtmail.txt file from the rtmail folder[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=#000000]       Kill “B:\rtmail\rtmail.txt”[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=blue]End If[/COLOR][/FONT][/SIZE]
 
[/COLOR]

I've read up on some stuff I've found in this forum and on the internet generally and none seem to cover a specific file, but cover mulitiply files with various file names to a single file.

Any assistance would be most appreciated.

John
 

JohnLee

Registered User.
Local time
Today, 08:59
Joined
Mar 8, 2007
Messages
692
Hi Folks,

Just in case anyone else outthere needs something like this, as I have now resolved my problem, with help of information from the Microsoft Help and Support web site, below is my code which works :

Code:
[COLOR=green][SIZE=3][FONT=Times New Roman]‘Checks to see if the rtmail.txt file exists in the B:\rtmail folder, if it does then[/FONT][/SIZE][/COLOR]
[SIZE=3][FONT=Times New Roman][COLOR=blue]If[/COLOR] FS.FileExists("B:\rtmail\rtmail.txt") = [COLOR=blue]True Then[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=green]‘Checks to see if the rtmail.tct file exists in the B:\rtmail.fof folder, if it does then[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=blue]If[/COLOR] FS.FileExists("B:\rtmail.fof\rtmail.txt") = [COLOR=blue]True Then[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Dim[/COLOR] SourceNum [COLOR=blue]As Integer      [/COLOR][COLOR=green]‘Declare the SourceNum variable as Integer[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Dim[/COLOR] DestNum [COLOR=blue]As Integer          [/COLOR][COLOR=green]‘Declare the DestNum variable as Integer[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]        [COLOR=green]‘Open the destination text file[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        DestNum = FreeFile()[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Open[/COLOR] "B:\rtmail.fof\rtmail.txt" [COLOR=blue]For Append As[/COLOR] DestNum[/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]        [COLOR=green]‘Open the source text file[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        SourceNum = FreeFile()[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Open[/COLOR] "B:\rtmail\rtmail.txt" [COLOR=blue]For Input As[/COLOR] SourceNum[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=green]‘Read each line of the source file and append it to the destination file[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman][COLOR=blue]            Do While Not [/COLOR]EOF(SourceNum)[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            [COLOR=blue]Line Input[/COLOR] #SourceNum, Temp[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            Print #DestNum, Temp[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Loop[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]        [COLOR=green]‘Close the files[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Close[/COLOR] #DestNum[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        [COLOR=blue]Close[/COLOR] #SourceNum[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]        Kill "B:\rtmail\rtmail.txt"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    [COLOR=blue]Else[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            [COLOR=green]'Copy the Return Mail text file to the new Folder[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            FS.CopyFile "B:\rtmail\rtmail.txt", "B:\remail.fof\rtmail.txt"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            [COLOR=green]'Delete the rtmail.txt file from the rtmail folder[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]            Kill "B:\rtmail\rtmail.txt"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    [COLOR=blue]End If[/COLOR][/FONT][/SIZE]
[COLOR=blue][SIZE=3][FONT=Times New Roman]End If[/FONT][/SIZE][/COLOR]

FAB

John
 
Last edited:

Users who are viewing this thread

Top Bottom