MQL5 to get file size

 

Hi,

I had a file data.txt which the file size are 0 bytes. and i had python program which will access to write some data into the file occasionally

Anyone know how do mql5 to get the filesize without open and accessing into data.txt ?


For example :

if

data.txt file size  =< 0 byte then print " No data "

else

print " got some data "


Thanks in Advance !

 
Paulf:

Hi,

I had a file data.txt which the file size are 0 bytes. and i had python program which will access to write some data into the file occasionally

Anyone know how do mql5 to get the filesize without open and accessing into data.txt ?


For example :

if

data.txt file size  =< 0 byte then print " No data "

else

print " got some data "


Thanks in Advance !

Not possible with MQL5, either use DLL calls or open the file with flag SHARED_READ, get the handle use FileSize() function and then close the file again.

 
Dominik Christian Egert #:

Not possible with MQL5, either use DLL calls or open the file with flag SHARED_READ, get the handle use FileSize() function and then close the file again.

Thanks for reply.

currently my another python program not able to access the file data.txt because of mql5 are accessing the data.txt on "every tick". So that cause of Error 13 permission denied at python side. thats the reason of im thinking to add a filter to check file size at first before let mql5 occupy/access data.txt so python program able to access to write data into the file.

If anyone had ideas/methods of how to do it are highly appreciated


thanks in advance

 
Dominik Christian Egert #:

Not possible with MQL5, either use DLL calls or open the file with flag SHARED_READ, get the handle use FileSize() function and then close the file again.

Sure it is possible.

  int fsize=FileGetInteger("data.txt",FILE_SIZE);
 
Paulf #:

Thanks for reply.

currently my another python program not able to access the file data.txt because of mql5 are accessing the data.txt on "every tick". So that cause of Error 13 permission denied at python side. thats the reason of im thinking to add a filter to check file size at first before let mql5 occupy/access data.txt so python program able to access to write data into the file.

If anyone had ideas/methods of how to do it are highly appreciated


thanks in advance

Use the appropriate share attributes. If the mql5 side is reading but the python is writing you need to use FILE_SHARE_WRITE in MQL5.

 
Alain Verleyen #:

Sure it is possible.

i will try this later. thanks again

 
Alain Verleyen #:

Use the appropriate share attributes. If the mql5 side is reading but the python is writing you need to use FILE_SHARE_WRITE in MQL5.

fileHandle = FileOpen("signal.txt", FILE_READ | FILE_WRITE | FILE_ANSI | FILE_SHARE_READ | FILE_SHARE_WRITE);

Do you mean if i just add this then python and mql5 can read and write the file at the same time ?


Thanks

 
You can use the file functions of kernel32.dll?
 
Alain Verleyen #:

Sure it is possible.

I looked it up and obviously missed the second signature...

I also thought it be possible, but checked and only saw file handle....

Edit:
I am tired today...
 
Paulf #:

fileHandle = FileOpen("signal.txt", FILE_READ | FILE_WRITE | FILE_ANSI | FILE_SHARE_READ | FILE_SHARE_WRITE);

Do you mean if i just add this then python and mql5 can read and write the file at the same time ?


Thanks

yes, but only use one of them read/write or shared read/write
 
Alain Verleyen #:

Sure it is possible.


void OnStart()
{
    // Specify the path to the file
    string file_path = "backupsignal.txt";

    // Get the file size
    long file_size = FileGetInteger(file_path, FILE_SIZE);

    // Print the file size
    Print("File size:", file_size);
}


Thanks