I am trying to add fields names to top of a CSV file. The issue is that the newly added line overwrites the first line in the passed text file. How to avoid the issue by moving first line down and inserting the new line.
BTW, I am using DBServer:CopyDelimited() to create the CSV file.
Code: Select all
function AddFieldsHeaders(cFileName as string, cDelim as string, aListBoxItems as array) as void pascal
local ptrHandle as ptr
LOCAL I as DWORD
LOCAL dwFieldsCount := ALen(aListBoxItems) as DWORD
IF (ptrHandle := FOpen2(cFileName, FO_READWRITE)) != F_ERROR
// Reset file position to beginning-of-file
FSeek(ptrHandle, 0)
FOR I := 1 upto dwFieldsCount
FWrite(ptrHandle, cDelim + aListBoxItems[I] + cDelim + iif( I < dwFieldsCount, ",",""))
next
FWrite(ptrHandle, CRLF)
FClose(ptrHandle)
ENDIF
return
Happy New Year!
Jamal