Error opening the file in a specific directory

 

hi

I just want the folder to be opened c:\

Thank you ;)

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

  
      string filename="c:\test.csv";

   int filehandle=FileOpen(filename,FILE_WRITE|FILE_CSV);
   if(filehandle<0)
     {
      Print("Failed to open ");
      Print("Error code ",GetLastError());
     }
 

   ResetLastError();

   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,TimeCurrent(),Symbol(),PERIOD_CURRENT);
      FileClose(filehandle);
      Print("FileOpen OK");
     }
 
  }
 

Note

For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox.

The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals.

"Named pipes" can be opened according to the following rules:

Pipe name is a string, which should have the following look: "\\servername\pipe\pipename", where servername - server name in the network, while pipename is a pipe name. If the pipes are used on the same computer, the server name can be omitted but a point should be inserted instead of it: "\\.\pipe\pipename". A client trying to connect the pipe should know its name.

FileFlush() and FileSeek() should be called to the beginning of a file between sequential operations of reading from the pipe and writing to it.

A special symbol '\' is used in shown strings. Therefore, '\' should be doubled when writing a name in MQL5 application. It means that the above example should have the following look in the code: "\\\\servername\\pipe\\pipename".

 
luenbo:

Note

For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox.

The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals.

"Named pipes" can be opened according to the following rules:

Pipe name is a string, which should have the following look: "\\servername\pipe\pipename", where servername - server name in the network, while pipename is a pipe name. If the pipes are used on the same computer, the server name can be omitted but a point should be inserted instead of it: "\\.\pipe\pipename". A client trying to connect the pipe should know its name.

FileFlush() and FileSeek() should be called to the beginning of a file between sequential operations of reading from the pipe and writing to it.

A special symbol '\' is used in shown strings. Therefore, '\' should be doubled when writing a name in MQL5 application. It means that the above example should have the following look in the code: "\\\\servername\\pipe\\pipename".

thnaks for replay

Can you please help me modify my code

;)

 
noorad2000:

thnaks for replay

Can you please help me modify my code

;)

try 
string filename="c:\\test.csv";
 
b3ck1:
try 

Did you read the reply of luenbo ? YOU CAN'T OPEN FILE outside "the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals."

Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
  • www.mql5.com
Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags - Documentation on MQL5
 
angevoyageur:

Did you read the reply of luenbo ? YOU CAN'T OPEN FILE outside "the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals."

Yes I read it, but he said that I could not do method
 

I use this trick but I could not

#import "kernel32.dll"
 bool CopyFileA(string lpExistingFileName, string lpNewFileName, bool failIfExists); 
#import
....

..
CopyFileA ("test.csv","c:\\"test.csv", true  )
 
noorad2000:
Yes I read it, but he said that I could not do method
I quoted your post  ^ ^ ^ ^ ^  so you know I am replying to you,  angevoyageur   quoted the post from  b3ck1  not from you so his reply is meant for  b3ck1   
 
RaptorUK:
I quoted your post  ^ ^ ^ ^ ^  so you know I am replying to you,  angevoyageur   quoted the post from  b3ck1  not from you so his reply is meant for  b3ck1   
Exactly
 
noorad2000:

I use this trick but I could not

Why do you need to do that ? It's a bad idea to bypass security when you do not even understand why it exists.

The best solution, if you really need to open file outside MQL5 folders, it to use named pipe : Communicating With MetaTrader 5 Using Named Pipes Without Using DLLs

 
angevoyageur:

Why do you need to do that ? It's a bad idea to bypass security when you do not even understand why it exists.

The best solution, if you really need to open file outside MQL5 folders, it to use named pipe : Communicating With MetaTrader 5 Using Named Pipes Without Using DLLs

Thank Alain 

But I do not want to send files between the two programs.

Reason: