FileIsExist always defaults to File exists already! what am i missing? - page 2

 
R4tna C #:

Yes - some functions may not be 100% reliable (in another thread there was a discussion of conversion functions which seem to be lacking, prompting many to write their own).

I suspect you need to consider FileIsExist() has such quirks and thus the workaround of reading the size could be a more reliable approach

So you say I need to become a "quirky coder" R4tna C?  :-) 

Jokes aside... Even if there were functions in the past lacking functionality, I still think it is a better idea to communicate the flaws / shortcomings of the platform - if they are legit - to the devs of MT5/MQL5.


Anyways, thanks again R4tna.


LMC

 
Alain Verleyen #:

This is normal behaviour using MQL5/Files with the Strategy Tester. The files there are deleted on each run, so your file never exists. I suppose it's written somewhere in the chaotic documentation.

If you want your file(s) to remain between different tester runs, then use the FILE_COMMON flag to use the common folder.

Hi Alain.

"normal behaviour" you say; I would never have thought? Is this then a flawed (IMO) feature? Would you perhaps know the reasoning behind implementing it in this manner? Apart from that file need to be handled within the sandbox. Or is it standard practice to use the common path as default?  

B.T.W. You nailed it with the documentation-reference.  :-)  Cannot remember that I've read anything of the sort.  Maybe I just missed it. Maybe it's not written (clearly) anywhere.

Anyways, thanks for confirming the craziness in all of this Alain. No more searching for a solution.  Just separate sets of logic that run for each environment, addressing the respective paths.


int OnInit()
{
   ResetLastError();
   
   if(MQLInfoInteger(MQL_TESTER) || MQLInfoInteger(MQL_DEBUG))
   {
      if(FileIsExist("TestFile.CSV", 0))
      {
         if(!FileDelete("TestFile.CSV", 0))
            Print("File Delete Error - ", _LastError);
      }      
      else
      {
         int H_File = FileOpen("TestFile.CSV", FILE_CSV|FILE_COMMON|FILE_WRITE|FILE_UNICODE, ",");
         
         if(H_File == INVALID_HANDLE)
         {
            Print("File Open Error - ", _LastError);
            
            return false;
         }
         
         FileFlush(H_File);
         
         FileClose(H_File);      
      }
   }   
   else
   {
      if(FileIsExist("TestFile.CSV"))
      {
         if(!FileDelete("TestFile.CSV"))
            Print("File Delete Error - ", _LastError);
      }      
      else   
      {
         int H_File = FileOpen("TestFile.CSV", FILE_CSV|FILE_WRITE|FILE_UNICODE, ",");
         
         if(H_File == INVALID_HANDLE)
         {
            Print("File Open Error - ", _LastError);
            
            return false;
         }
         
         FileFlush(H_File);
         
         FileClose(H_File);
      }
   }
   return INIT_SUCCEEDED; 
}

The above is not an elegant solution, but it will work. Almost as sneaky as R4tna. ;-)  

In the end, I still don't get it! But at least I'm not going to drive myself bonkers anymore - Thanks Alain!

LMC
 
lmclark #:
So you say I need to become a "quirky coder" R4tna C?  :-) 

Jokes aside... Even if there were functions in the past lacking functionality, I still think it is a better idea to communicate the flaws / shortcomings of the platform - if they are legit - to the devs of MT5/MQL5.


Anyways, thanks again R4tna.


LMC

Not so much quirky, so often tech does not work as expected (even with the largest vendors) and often the anomalies never get fixed - so one has to find other ways

All the best