One or several flags can be specified when opening a file. This is a combination of flags. The combination of flags is written using the sign of logical OR (|), which is positioned between enumerated flags. For example, to open a file in CSV format for reading and writing at the same time, specify the combination FILE_READ|FILE_WRITE|FILE_CSV.
Example:
int filehandle=FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV);
There are some specific features of work when you specify read and write flags:
- If FILE_READ is specified, an attempt is made to open an existing file. If a file does not exist, file opening fails, a new file is not created.
- FILE_READ|FILE_WRITE – a new file is created if the file with the specified name does not exist.
- FILE_WRITE – the file is created again with a zero size.
Is it the answer? I caannot get the answer here)), I need some option to use to open the file with addition, not replacement or deletion.
I use this code, that does not work...
int f=FileOpen("WriteString.csv",FILE_READ|FILE_WRITE|FILE_CSV); FileWriteString(f,"1111111....\r\n");
Thanks for your kind answer.
Maybe Fernando Carreiro?
As usual, his answers are useful))

Would you like a water or coffee while you wait?... Ask someone who knows how to read for help and see the article below... There's even the code ready:
MQL5 Programming Basics: Files
Dmitry Fedoseev, 2016.11.04 15:19
This practice-oriented article focuses on working with files in MQL5. It offers a number of simple tasks allowing you to grasp the basics and hone your skills.Would you like a water or coffee while you wait?... Ask someone who knows how to read for help and see the article below... There's even the code ready:
Thanks Viicius, I will have a look now. However, I have not transitioned to MT5 yet, I am still in MT4, let me see, if I can apply it for codes in MQL4.
Regards
Bahman
OK, if the error persists, please post your code (using the CODE button - Alt+S) so we can identify why it isn't working.
OK, if the error persists, please post your code (using the CODE button - Alt+S) so we can identify why it isn't working.
dear Vinicicus,
Thanks for your idea, it looks now I can understand your point of view. I mean if I include READ and WRITE options, then I can read the content of the file,
save it into a string variable and then when I need to save the file, I can add it onto the beginning of newly added text and save them into a file together?
I hope, you meant this, it was a good idea, and thanks a lot for this. It looks my problem gets solved.
Regards
Bahman
dear Vinicicus,
Thanks for your idea, it looks now I can understand your point of view. I mean if I include READ and WRITE options, then I can read the content of the file,
save it into a string variable and then when I need to save the file, I can add it onto the beginning of newly added text and save them into a file together?
I hope, you meant this, it was a good idea, and thanks a lot for this. It looks my problem gets solved.
Regards
Bahman
The following function I have made to add new text onto the end of the CSV file... Thanks a lot:
LineAdd(f,"1,2,3"); //function calling...
void LineAdd(int f,string s) {while(!FileIsEnding(f))FileReadString(f); FileWriteString(f,s+"\n");return;}

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to add some information into the end of CSV or TXT file, but every time I open the file with FileOpen and write the text there, it erases all information and write a new text..
But I need to add the new information into the end of the file, while keeping the previous text as well. Kind of incremental approach.
I need to keep previous text after closing file with FileClose and opening again with FileOpen.
Any idea? How to get a file with increasing volume in every writing there?
Look forward to hearing from you.
Thanks.
Bahman