How to the id:5002 problem of FileOpen? - page 2

 

Good afternoon. I've got similar problem above. But the problem is, when I just put the filename, I got error 5004. If I specify the path I got 5002. Did I miss something here?

string filename = TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files\\output.txt";
//Print(filename);
ResetLastError();
int file_handle=FileOpen("output.txt", FILE_TXT|FILE_READ);
//Print(file_handle);
string up, down, sideway;
up = down = sideway = 0;
if (file_handle!=INVALID_HANDLE){
   Print("read");
   up=FileReadString(file_handle);
   down = FileReadString(file_handle);
   sideway = FileReadString(file_handle);
} else{
   Print("file open error: ", GetLastError());
} FileClose(file_handle);
I put the file in Files folder. I've checked it's indeed the file is exist as specified in the filename string.
 
Alain Verleyen #:

Once again :

Thanks, just want to check can i write my files in a subfolder in this common folder.. 


Example

Right now it is creating files in " C:\Users\******\AppData\Roaming\MetaQuotes\Terminal\Common\Files


i want files in 

C:\Users\******\AppData\Roaming\MetaQuotes\Terminal\Common\Files\1

C:\Users\******\AppData\Roaming\MetaQuotes\Terminal\Common\Files\2

 
mallaravi #:

Thanks, just want to check can i write my files in a subfolder in this common folder.. 


Example

Right now it is creating files in " C:\Users\******\AppData\Roaming\MetaQuotes\Terminal\Common\Files


i want files in 

C:\Users\******\AppData\Roaming\MetaQuotes\Terminal\Common\Files\1

C:\Users\******\AppData\Roaming\MetaQuotes\Terminal\Common\Files\2

I think i solved it..


this is working

   filename1 = "//1//"+"Summary.csv";

  filehandle1=FileOpen(filename1,FILE_COMMON|FILE_WRITE|FILE_CSV);

 

Hello, I have problems when I run my code in the expert tab it gives me errors 5002 and 5004 2024.08.03 13:06:14.710 LunariaRNNPest (Step Index,H1) Verifying the directory: Common\Files\2 2024.08.03 13:06:14.711 LunariaRNNPrueba (Step Index,H1) Directory verified/created successfully: Common\Files\2 2024.08.03 13:06:14.711 LunariaRNNPreba (Step Index,H1) Trying to create the flag file in: Common\Files\2\Step Index_run_flag.txt 2024.08.03 13:06:14.713 LunariaRNNPrail (Step Index,H1) Error creating flag file for: Step Index. Error: 5004

I am creating this neural network for various symbols. I appreciate your support please

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    for(int symIdx = 0; symIdx < ArraySize(symbolsToTrade); symIdx++)
    {
        string symbolToTrade = symbolsToTrade[symIdx];
        string model_path = model_paths[symIdx];
        string scaler_path = scaler_paths[symIdx];
        string data_path = data_paths[symIdx];
        string predictions_file_path = prediction_paths[symIdx];
        string flag_path = flag_paths[symIdx];
        
        // Verificar si el directorio existe, si no, crearlo
        string directory = "Common\\Files\\2";
        Print("Verificando el directorio: ", directory);
        if (!CreateDirectoryIfNotExist(directory))
        {
            Print("Error al crear el directorio de bandera para: ", symbolToTrade);
            continue; // Si no se puede crear el directorio, saltar al siguiente símbolo
        }

        // Intentar crear el archivo de bandera
        string filename = directory + "\\" + symbolsToTrade[symIdx] + "_run_flag.txt";
        Print("Intentando crear el archivo de bandera en: ", filename);
        int filehandle = FileOpen(filename, FILE_WRITE|FILE_TXT|FILE_COMMON);
        if (filehandle != INVALID_HANDLE)
        {
            FileClose(filehandle);
            Print("Archivo de bandera creado exitosamente para: ", symbolToTrade);
        }
        else
        {
            Print("Error al crear el archivo de bandera para: ", symbolToTrade, ". Error: ", GetLastError());
        }
    }
}
 
Sarah Vera #:
       string directory = "Common\\Files\\2";
        string filename = directory + "\\" + symbolsToTrade[symIdx] + "_run_flag.txt";

You can't read (or write) outside the sandbox with normal code.
          File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)

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.
          FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)
and FolderDelete using TERMINAL_DATA_PATH - General - MQL5 programming forum (2017)