Combine two text files into one text file

From NSIS Wiki

Author: Afrow UK (talk, contrib)


Description

This script will combine one text file with another text file and output the combined text into a new file.

Usage

Push C:\temp3.txt #Output file
Push C:\temp1.txt #File 1
Push C:\temp2.txt #File 2 to be joined onto file 1
Call JoinFiles

== Order of Combination ==

File 2
[divider]
File 1

The Function

Function JoinFiles
Exch $1
Exch
Exch $3
Exch
Exch 2
Exch $4
Exch 2
Push $0
Push $2
Push $5
  GetTempFileName $5
  SetDetailsPrint none
  CopyFiles $1 $5
  SetDetailsPrint both
FileOpen $0 $5 a
FileOpen $2 $3 r
loop1:
  FileRead $0 $1
  IfErrors doneloop1
Goto loop1
doneloop1:
  FileWrite $0 "$\r$\n$\r$\n$\r$\n-=hello=-$\r$\n$\r$\n$\r$\n" #Optional [divider]
loop2:
  FileRead $2 $1
  FileWrite $0 $1
  IfErrors done
Goto loop2
done:
   FileClose $2
   FileClose $0
  SetDetailsPrint none
  IfFileExists $4 0 +2
  Delete $4
  CopyFiles $5 $4
  Delete $5
  SetDetailsPrint both
Pop $5
Pop $2
Pop $0
Pop $4
Pop $3
Pop $1
FunctionEnd

Wrote by me to combine two batch files.

Use $\r$\n to go to a new line, and use $\r$\n$\r$\n to jump two lines, and so-on. -Stu (Afrow UK)

Personal tools
donate