Download MetaTrader 5

Append text line at the beginning of file?

To add comments, please log in or register
arcull
149
arcull  

Hi,

title says it all, normally when you use FileWrite method, string is appended to the end of file. However I would like the other way around if possible, that is to append the new strings at the beginning without overwriting existing content, so that the last string appended is always on top of file. Is this possible at all? Much thanks.

Alain Verleyen
Moderator
34443
Alain Verleyen  
arcull:

Hi,

title says it all, normally when you use FileWrite method, string is appended to the end of file.

However I would like the other way around if possible, that is to append the new strings at the beginning without overwriting existing content, so that the last string appended is always on top of file. Is this possible at all? Much thanks.

Not possible. You have to read the existing content, append your new data and write all the file again.
arcull
149
arcull  
Alain Verleyen:
Not possible. You have to read the existing content, append your new data and write all the file again.

Alain thanks, do you have any idea how would I read the file from end to the beginning? I have ASCII file with CRLF, something like this:


HOUR;MIN;BID;ASK

8;30;1,1223;1,1224

9;31;1,1226;1,1228

10;32;1,1221;1,1223


Or should I consider using MySQL instead, thanks.

Alain Verleyen
Moderator
34443
Alain Verleyen  
arcull:

Alain thanks, do you have any idea how would I read the file from end to the beginning? I have ASCII file with CRLF, something like this:


HOUR;MIN;BID;ASK

8;30;1,1223;1,1224

9;31;1,1226;1,1228

10;32;1,1221;1,1223


Or should I consider using MySQL instead, thanks.

A loop with FileReadString().
arcull
149
arcull  
Alain Verleyen:
A loop with FileReadString().
And check every loop if character is CR or LF, so that you know you are in new line?
arcull
149
arcull  
But I should read char by char, FileReadString() can't read backwards, and I don't know in advance how much offset to make before new FileReadString.
To add comments, please log in or register