Files: how to read file attributes, for example "last time the file was saved / changed"

 

Hello,

thanks to available documentation and articles, I can now manage to read a file with multiple columns to an array in my MQL5 program.

Now I am concerned that the file is read all the time, even though it was not updated.

I only want to read the file, when it was updated.

So I am looking for a possibility to read this attribute from the file.

I have searched quite a bit but did not find this.

Thanks a lot in advance if you can help me!!!

 
KjLNi:

Hello,

thanks to available documentation and articles, I can now manage to read a file with multiple columns to an array in my MQL5 program.

Now I am concerned that the file is read all the time, even though it was not updated.

I only want to read the file, when it was updated.

So I am looking for a possibility to read this attribute from the file.

I have searched quite a bit but did not find this.

Thanks a lot in advance if you can help me!!!

FileGetInteger("your file", FILE_ACCESS_DATE)
 

Hello there, as you can tell, I am a self-tough programmer. However, if some other newbie has the same question, this finding might help you.

Here below is a way of checking if a file has been updated since the last time it was read.

This part of coding can be used as a sub-routine.

The variable "Filename" has been defined earlier as a user-input parameter.

I am working with a CSV file which is stored in the "common" folder.

With best regards!!!


//+------------------------------------------------------------------+

//|   is the File Updated?                                           |

//+------------------------------------------------------------------+

 bool IsFileUpdated(string FileName)

 {

  // a global parameter "PrevFile=0" has been defined earlier in the program

   long   l=0; 

   long filetime_0 = 0;



   int handle=FileOpen(FileName,FILE_READ|FILE_ANSI|FILE_CSV|FILE_COMMON, ",");

   if(handle!=INVALID_HANDLE) 

   {

   filetime_0 = FileGetInteger(handle, FILE_MODIFY_DATE);

   FileClose(handle);    

   }

      

   if(filetime_0 == PrevFile)

     {return false;}

   else

     {PrevFile = filetime_0;

     return true; // when checking, we found the file updated. Now we set the time to the same level, for the next check

     }

}

 
Use the </> button to insert your code.
Reason: