Download MetaTrader 5

Help! The File Can't be Append?

To add comments, please log in or register
virusx1984
13
virusx1984  

I saw in the MQL4 Document:

  • 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.
so the file that exists can't be append? 
Carl Schreiber
7549
Carl Schreiber  
Well this is the intended behaviour. What can you read from a file that does not exist?
whroeder1
16321
whroeder1  
virusx1984: so the file that exists can't be append? 
Of course you can; open read/write and seek to the end.
virusx1984
13
virusx1984  
WHRoeder:
virusx1984: so the file that exists can't be append? 
Of course you can; open read/write and seek to the end.

Thank you! How to seek to the end? Could you give me an example?
whroeder1
16321
whroeder1  
virusx1984 How to seek to the end? Could you give me an example?
  1. RTFM List of MQL4 Functions - MQL4 Documentation -> File Functions - MQL4 Documentation -> FileSeek - MQL4 Documentation
  2. RTFB MQL4 Tutorial -> File Operations - Standard Functions - MQL4 Tutorial -> FileSeek - MQL4 Documentation
  3.       int      CREATE   = FILE_WRITE|FILE_TXT|FILE_ANSI;
          int      APPEND   = FILE_READ|CREATE;
          string   fileName = WindowExpertName() + ".DBG";
          HANDLE   handle   = FileOpen(fileName, APPEND);
          if(handle != INVALID_HANDLE){
             FileSeek(handle, 0, SEEK_END);
             FileWrite(handle, s);
             FileClose(handle);
    
    Is that so hard?
To add comments, please log in or register