Download MetaTrader 5

b617: FILE_BIN: reading whole file fails??

To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
Carl Schreiber
6609
Carl Schreiber 2014.03.20 14:19 

This I read in the reference:

string  FileReadString(
   int  file_handle,     // File handle
   int  length=-1        // Length of the string
   );

...
When reading from a bin-file. the length of a string to read must be specified. 
When reading from a txt-file the string length is not required, 
and the string will be read from the current position to the line feed character "\r\n". 
When reading from a csv-file, the string length isn't required also, 
the string will be read from the current position till the nearest delimiter 
or till the text string end character.

Ok, now I want to read my file in the whole and I write:

        int handle, szFile, noLines;
        string strFile, arrFile[];
        handle = FileOpen(fName, FILE_SHARE_READ | FILE_READ | FILE_BIN);
        szFile = FileSize(handle);
        strFile = FileReadString(handle, szFile);
        noLines = StringSplit(strFile,"\n",arrFile);
        Print("My File with 20 lines and 2k has now ",noLines," Line?? FileSize: ",szFile);
I get:
 2014.03.20 15:09:42.509	test EURUSD,M1: My File with 20 lines and 2k has now 1 Line?? FileSize: 2048

Is that intended?


Beside that I would appreciate if the variable types of FileSize (ulong) and the length (int) to read would match:

ulong  FileSize(
   int  file_handle    // File handle
   );
..
int  FileWriteString(
   int           file_handle,    // File handle
   const string  text_string,    // string to write
   int           length=-1       // number of symbols
   );

You may set as default (read all or do not use) the max of ulong?




To add comments, please log in or register