Help! The File Can't be Append?

Back to topics list To post a new topic, please log in or register
avatar
2
virusx1984 2015.11.11 17:10
 

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? 

 

avatar
2017
gooly 2015.11.11 17:47 #
 
Well this is the intended behaviour. What can you read from a file that does not exist?
avatar
12988
WHRoeder 2015.11.11 19:03 #
 
virusx1984: so the file that exists can't be append? 
Of course you can; open read/write and seek to the end.

avatar
2
virusx1984 2015.11.12 00:30 #
 
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?
avatar
12988
WHRoeder 2015.11.12 17:14 #
 
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?
Back to topics list  

To add comments, please log in or register