How to insert a source text file into a target text file at a specific line?
;==========================================================================================================================================
;
; How to insert a source text file into a target text file at a specific line?
;
;------------------------------------------------------------------------------------------------------------------------------------------;
; Q: How do I program Winbatch to insert the source file's lines
; in between the fourth and fifth lines of the target file?
;
; A: Take lines 1..4 from target file, append complete source file and
; append the remaining lines of the target file giving the new target file.
;------------------------------------------------------------------------------------------------------------------------------------------
; (c)Detlev Dalitz.20080818.20100228.
;==========================================================================================================================================

DirChange (DirScript ())

strFolder = ""

strFilename1 = strFolder : "File.Source.txt"   ; Source file.
strFilename2 = strFolder : "File.Target.txt"   ; Target file.
strFilename3 = strFolder : "File.Combined.txt" ; Combined file.

intLines = 4


hdlF3 = FileOpen (strFilename3, "WRITE")

hdlF2 = FileOpen (strFilename2, "READ")
For intLine = 1 To intLines
   strLine = FileRead (hdlF2)
   If strLine == "*EOF*" Then Break
   FileWrite (hdlF3, strLine)
Next

hdlF1 = FileOpen (strFilename1, "READ")
While @TRUE
   strLine = FileRead (hdlF1)
   If strLine == "*EOF*" Then Break
   FileWrite (hdlF3, strLine)
EndWhile
hdlF1 = FileClose (hdlF1)

While @TRUE
   strLine = FileRead (hdlF2)
   If strLine == "*EOF*" Then Break
   FileWrite (hdlF3, strLine)
EndWhile
hdlF2 = FileClose (hdlF2)

hdlF3 = FileClose (hdlF3)

;blnResult = FileMove (strFilename3, strFilename2, @FALSE)
;blnResult = FileDelete (strFilename1)

Exit
;==========================================================================================================================================