//+------------------------------------------------------------------+ //| Demo_FileMove.mq5 | //| Copyright 2013, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" //--- display the window of input parameters when launching the script #property script_show_inputs //--- input parameters input string InpSrcName="data.txt"; input string InpDstName="newdata.txt"; input string InpSrcDirectory="SomeFolder"; input string InpDstDirectory="OtherFolder"; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { string local=TerminalInfoString(TERMINAL_DATA_PATH); string common=TerminalInfoString(TERMINAL_COMMONDATA_PATH); //--- receive file paths string src_path; string dst_path; StringConcatenate(src_path,InpSrcDirectory,"//",InpSrcName); StringConcatenate(dst_path,InpDstDirectory,"//",InpDstName); //--- check if the source file exists (if not - exit) if(FileIsExist(src_path)) PrintFormat("%s file exists in the %s\\Files\\%s folder",InpSrcName,local,InpSrcDirectory); else { PrintFormat("Error, %s source file not found",InpSrcName); return; } //--- check if the result file already exists if(FileIsExist(dst_path,FILE_COMMON)) { PrintFormat("%s file exists in the %s\\Files\\%s folder",InpDstName,common,InpDstDirectory); //--- file exists, moving should be performed with FILE_REWRITE flag ResetLastError(); if(FileMove(src_path,0,dst_path,FILE_COMMON|FILE_REWRITE)) PrintFormat("%s file moved",InpSrcName); else PrintFormat("Error! Code = %d",GetLastError()); } else { PrintFormat("%s file does not exist in the %s\\Files\\%s folder",InpDstName,common,InpDstDirectory); //--- the file does not exist, moving should be performed without FILE_REWRITE flag ResetLastError(); if(FileMove(src_path,0,dst_path,FILE_COMMON)) PrintFormat("%s file moved",InpSrcName); else PrintFormat("Error! Code = %d",GetLastError()); } //--- the file is moved; let's check it out if(FileIsExist(dst_path,FILE_COMMON) && !FileIsExist(src_path,0)) Print("Success!"); else Print("Error!"); } //+------------------------------------------------------------------+