FileClose

 

Hello,


i have problems with file close,

I read a file, and close it after

bool FileLesen(string filename, string KommeVon)
  {
   ResetLastError();
   bool value = 0;

   int file_handle=FileOpen(filename,FILE_READ|FILE_CSV);
   if(file_handle!=INVALID_HANDLE)
     {
      //while(!FileIsEnding(file_handle))
      //  {
      value=FileReadBool(file_handle);
      // }
      FileClose(file_handle);
     }
   if(GetLastError() != 0)
      Print(__FUNCTION__,": Failure in reading file, ",filename, ", kommend von - ",KommeVon," ", GetLastError());
}

that works normally perfekt, but sometimes I get an error Messages 5001, not more than 64 file can be open.

Is there a way, to check, which files are open?

The main problem, FileClose is a void with no return value, normally I will check, if the closing was ok, but in a void I can't do it.

can it work with a safety closing before end of my function?

FileFindClose(file_handle); 
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
Predefined Macro Substitutions - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
amando:

Hello,


i have problems with file close,

I read a file, and close it after

that works normally perfekt, but sometimes I get an error Messages 5001, not more than 4 file can be open.

Is there a way, to check, which files are open?

The main problem, FileClose is a void with no return value, normally I will check, if the closing was ok, but in a void I can't do it.

can it work with a safety closing before end of my function?

Are you running
FileLesen()

in a speedy loop? or from several indicators/EAs at the same time?

If so, you can consider using the flag FILE_SHARE_READ ...

;)

 
Flavio Jarabeck:
Are you running

in a speedy loop? or from several indicators/EAs at the same time?

If so, you can consider using the flag FILE_SHARE_READ ...

;)

Evrything from the same ea.

maybe from diffrent functions in the ea, but it should close after.