How to prepend or append additional text into text file?
;==========================================================================================================================================
;
; How to prepend or append additional text into existing text file?
;
;------------------------------------------------------------------------------------------------------------------------------------------
; (c)Detlev Dalitz.20111230.
;==========================================================================================================================================


DirChange (DirScript ())

strFileThis = IntControl (1004, 0, 0, 0, 0)
strTestFile = ItemReplace ("test.txt", -1, strFileThis, ".") ; Define name for the test file (based on this script's filename).


; Create test file with three lines.
intBytesWritten = FilePut (strTestFile, "text line 1" : @CRLF : "text line 2" : @CRLF : "text line 3")

Message ("Test 1", FileGet (strTestFile))


; Prepend one line at top of the file.
intBytesWritten = FilePut (strTestFile, "*** TOP ***" : @CRLF : FileGet (strTestFile))

Message ("Test 2", FileGet (strTestFile))


; Append one line at bottom of the file.
intBytesWritten = FilePut (strTestFile, FileGet (strTestFile) : @CRLF : "*** BOTTOM ***")

Message ("Test 3", FileGet (strTestFile))

:CANCEL
Exit