File Exists?

 
I have a EA that should react on the existence of a file.
So I just call handle=FileOpen(FileName, FILE_CSV|FILE_READ, ';'); and if the handle > 0 the file exists.
However now on every tick I get a message in the "expert"-part of the terminal: cannot open file .....
The logfile from the "expert"-part will become bgger and bigger.
Is there a way to disable those messages? Or another way to check the existance of a file?
 
check file existence in the init function, it runs only once like this

int handle;
 
int init()
{
   handle=FileOpen(....
}
 
int start()
{
   if(handle<0) { no file }



 

The file does not exist if:
1. FileOpen returned -1.
2. GetLastError = ERR_CANNOT_OPEN_FILE (4103)

 

Thanks for the answers, but I think my problem isn't understood. I know how to check if a file doesn't exists. My problem is that my EA should do that check on every tick. That means that on every tick I get some kind of errormessage in the "expert" tab. Which means the logs become huge. Is there a method to disable that message?

 
I don't get it. Are you going to create file manually at some point in the future?
If so, then instead of checking for existing file, create file upfront and put some check in the first line if file is valid or not and you can change it manually.
This way you can open file check it and close it on every tick.
Or better yet, use global variables to set if file needs to be opened or not, this way you wont have to open file until actually needed.
 
irusoh1 wrote:
I don't get it. Are you going to create file manually at some point in the future?
If so, then instead of checking for existing file, create file upfront and put some check in the first line if file is valid or not and you can change it manually.
This way you can open file check it and close it on every tick.
Or better yet, use global variables to set if file needs to be opened or not, this way you wont have to open file until actually needed.

Thanks. Your first suggestion (check in the first line) I try to avoid.
Your second sounds a lot better, but I don't understand what you mean with global variables and how an EA can access them.
 
check global variables in mql editor help.
then press F3 menu option Tools/Global variables. You can create them or set them manually. So create gbReadFile=0 then set it to 1 when you want EA to read file. EA should retrieve it and check every time in start() function.
 
irusoh1:
check global variables in mql editor help.
then press F3 menu option Tools/Global variables. You can create them or set them manually. So create gbReadFile=0 then set it to 1 when you want EA to read file. EA should retrieve it and check every time in start() function.

You mean the global variables from MT4. They don't help.

I just want to have some way to communicate between a windows program and MT4. The normal solution is building a DLL. Another solution could be that the windowsprogram creates a file in the experts/file-folder. An EA could look if that file exists and maybe read the data in it. My first idea was simply look if the file exists. But that means a lot of those errormessages. Now I have to do what I wanted to avoid, not looking whether the file exists, but read it and look at the data in it.

Thanks for your input.
 
If file opened as read only, this error message is not logged now. Wait for next build update.
 

There is Windows _findfirst function.
 
Thanks for the answers. There are several possibilities to communicate between MT4 and windows. A DLL could be used (with _findfirst or fileexist-functions), or I could use global variables like irusoh1 pointed out, but for some reasons I want it to solve with some function like FileExist. I understand from stringo, that the best solution is to wait until the next build.