Alain Verleyen:
mql5 is using Unicode string, you would need to use the W version of the functions : MoveFileW, CopyFileW
mql5 is using Unicode string, you would need to use the W version of the functions : MoveFileW, CopyFileW
Thanks Alain,
Here's the working version:
//+------------------------------------------------------------------+ //| JavascriptTest.mq5 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #import "kernel32.dll" int MoveFileW(string ExistingFilename, string NewFilename); int CopyFileW(string strExistingFile, string strCopyOfFile, int OverwriteIfCopyAlreadyExists); int GetLastError(); #import //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- const int handle2 = ::FileOpen("JavascriptFile.jsX", FILE_WRITE | FILE_TXT ); if (handle2 != INVALID_HANDLE) { FileWrite(handle2, "var data = 123; "); FileClose(handle2); } else { Print ("Write Error ", GetLastError()); } string FileFrom = "JavascriptFile.jsX"; if (FileIsExist(FileFrom)) Print (FileFrom, " Found!"); else Print (FileFrom, " not Found"); string PathFileFrom = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\" + FileFrom; string PathFileTo = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\" + "JavascriptFile.js"; Print (PathFileFrom); //MoveFileW(PathFileFrom, PathFileTo); //Print("MoveFileW error ",kernel32::GetLastError()); CopyFileW(PathFileFrom, PathFileTo,0); Print("CopyFileW error ",kernel32::GetLastError()); } //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to rename a file using kernel32 with following code:
In my case the script returns the file being found, but both copy and move function return error code 2 (File not found), even though the file exists. If i copy the PathFileFrom path from the Experts Log and paste into Explorer, the file prompts. What could be the issue?