MQL4参考 文件函数 FileGetInteger


Gets an integer property of a file. There are two variants of the function.

1. Get a property by the handle of a file.

long  FileGetInteger(
   int                         file_handle,   // File handle
   ENUM_FILE_PROPERTY_INTEGER  property_id    // Property ID

2. Get a property by the file name.

long  FileGetInteger(
   const string                file_name,            // File name
   ENUM_FILE_PROPERTY_INTEGER  property_id,          // Property ID
   bool                        common_folder=false   // The file is viewed in a local folder (false)
   );                                                // or a common folder of all terminals (true)



[in]  File descriptor returned by FileOpen().


[in]  File name.


[in]  File property ID. The value can be one of the values of the ENUM_FILE_PROPERTY_INTEGER enumeration. If the second variant of the function is used, you can receive only the values of the following properties: FILE_EXISTS, FILE_CREATE_DATE, FILE_MODIFY_DATE, FILE_ACCESS_DATE and FILE_SIZE.


[in]  Points to the file location. If the parameter is false, terminal data folder is viewed. Otherwise it is assumed that the file is in the shared folder of all terminals \Terminal\Common\Files (FILE_COMMON).

Return Value

The value of the property. In case of an error, -1 is returned. To get an error code use the GetLastError() function.

If a folder is specified when getting properties by the name, the function will have error 5018 (ERR_MQL_FILE_IS_DIRECTORY) in any case, though the return value will be correct.


The function always changes the error code. In case of successful completion the error code is reset to NULL.


//--- display the window of input parameters when launching the script
#property script_show_inputs
//--- input parameters
input string InpFileName="data.csv";
input string InpDirectoryName="SomeFolder";
//| Script program start function                                    |
void OnStart()
   string path=InpDirectoryName+"//"+InpFileName;
   long   l=0;
//--- open the file
   int handle=FileOpen(path,FILE_READ|FILE_CSV);
      //--- print all information about the file
      Print(InpFileName," file info:");
      //--- close the file
      PrintFormat("%s file is not opened, ErrorCode = %d",InpFileName,GetLastError());
//| Display the value of the file property                           |
void FileInfo(const int handle,const ENUM_FILE_PROPERTY_INTEGER id,
              long l,const string type)
//--- receive the property value
      //--- the value received, display it in the correct format
         Print(EnumToString(id)," = ",l ? "true" : "false");
         Print(EnumToString(id)," = ",(datetime)l);
         Print(EnumToString(id)," = ",l);
      Print("Error, Code = ",GetLastError());

See also

File Operations, File Properties