I took a sample script from FileCopy documentation.
I supplemented it with your check for file existence.
The result is the same - the script does not see the file.
//+------------------------------------------------------------------+//| prob.mq5 |//| Copyright 2023, MetaQuotes Ltd. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2023, MetaQuotes Ltd."#property link"https://www.mql5.com"#property version"1.00"//--- покажем окно входных параметров при запуске скрипта#property script_show_inputs//--- входные параметрыinputstring InpSrc="source.txt"; // источникinputstring InpDst="destination.txt"; // копияinputint InpEncodingType=FILE_ANSI; // ANSI=32 или UNICODE=64//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
if(!FileIsExist("InpSrc",0)) // FILE_COMMONPrint("Нет в папке такого файла!");
//--- отобразим содержимое источника (он должен существовать)if(!FileDisplay(InpSrc)) // 5004 Ошибка открытия файлаreturn;
//--- проверим, существует ли уже файл копии (не обязан быть создан)if(!FileDisplay(InpDst))
{
//--- файл копии не существует, копирование без флага FILE_REWRITE (правильное копирование)if(FileCopy(InpSrc,0,InpDst,0))
Print("File is copied!");
elsePrint("File is not copied!");
}
else
{
//--- файл копии уже существует, попробуем скопировать без флага FILE_REWRITE (неправильное копирование)if(FileCopy(InpSrc,0,InpDst,0))
Print("File is copied!");
elsePrint("File is not copied!");
//--- содержимое файла InpDst останется прежним
FileDisplay(InpDst);
//--- скопируем еще раз с флагом FILE_REWRITE (правильное копирование при существовании файла)if(FileCopy(InpSrc,0,InpDst,FILE_REWRITE))
Print("File is copied!");
elsePrint("File is not copied!");
}
//--- получили копию файла InpSrc
FileDisplay(InpDst);
}
//+------------------------------------------------------------------+//| Чтение содержимого файла |//+------------------------------------------------------------------+bool FileDisplay(conststring file_name)
{
//--- сбросим значение ошибкиResetLastError();
//--- откроем файлint file_handle=FileOpen(file_name,FILE_READ|FILE_TXT|InpEncodingType);
if(file_handle!=INVALID_HANDLE)
{
//--- отобразим в цикле содержимое файлаPrint("+---------------------+");
PrintFormat("File name = %s",file_name);
while(!FileIsEnding(file_handle))
Print(FileReadString(file_handle));
Print("+---------------------+");
//--- закроем файлFileClose(file_handle);
return(true);
}
//--- не удалось открыть файлPrintFormat("%s is not opened, error = %d",file_name,GetLastError());
return(false);
}
//+------------------------------------------------------------------+
There must be some reason for such behaviour. It is necessary to put forward hypotheses and test them sequentially. For example:
Is there a Russian letter ('s' or 'e') in some of the file names? You can take harsher names like "1.bin"
Is this the right data directory? Check if it is opened from the terminal menu or MetaEditor.
Does the script consider this particular directory as the current one? Add two commands to the beginning of OnStart(): open a new file with creation and close it. See that it appears in the expected directory
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Unfortunately, your code didn't work for me.
I don't know how to help you.
I checked it again, it works.
As you can see, it copies anywhere and with different names and even with a change of extension.
PS Check for a file, maybe you are confused somewhere.
paste in the beginning of the script
I don't know how to help you.
Checked it again, it's working.
As you can see it copies anywhere and with different names and even with extension change.
PS Check for a file, maybe you are confused somewhere.
paste in the beginning of the script
Thanks for the humour!
I'll check it tonight
Thanks for the humour!
I'll check it out tonight
I added your humour to the script and this is what happened:
Although there is a File.csv file in the Files folder, the script doesn't see it and prints:
Fuck off, there is no such file in the folder!
false
false
false
Just fantastic!!!
Just fantastic!!!
There's no such thing as fantastic.
Make the folder properties visible file extension.
As I see you have a file named File.csv.txt, and you are trying to find File.csv, of course you can't find it.
The fiction continues.
I took a sample script from FileCopy documentation.
I supplemented it with your check for file existence.
The result is the same - the script does not see the file.
Hello, Alexander.
There must be some reason for such behaviour. It is necessary to put forward hypotheses and test them sequentially. For example:
- Is there a Russian letter ('s' or 'e') in some of the file names? You can take harsher names like "1.bin"
- Is this the right data directory? Check if it is opened from the terminal menu or MetaEditor.
- Does the script consider this particular directory as the current one? Add two commands to the beginning of OnStart(): open a new file with creation and close it. See that it appears in the expected directory
I haven't thought of anything else yetThe fiction continues.
Onemore time. You need to name a file with the extension of that file.
You have created a file with the extension .txt and the name File.csv
So the full name of the file to be specified in the programme will be File.c sv .txt.
You have disabled display of file extensions in the folder properties in Windows, that's why you have such a confusion with file names.
There is no fantasy.
Make the file extension visible in the folder properties.
As I see you have a file named File.csv.txt, and you are trying to find File.csv, of course you can't find it.
Thank you very much! That was the problem. Without you I would not have been able to find the error. I wish you success!
Alexander, good afternoon!
It turns out that the file must be closed before rewriting it from the sandbox to the Tester folder.
Otherwise it doesn't work.
It took me a long time to figure it out!!!
Regards, Alexander
Alexander, good afternoon!
It turns out that the file must be closed before rewriting it from the sandbox to the Tester folder.
Otherwise it doesn't work.
What if it does? ))))
Provided that there is no file with that name in the destination folder.