Initial commit: MQL5 Scripts Collection (MetaTrader 5)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# 🚀 Unlock the Power of Trading!
|
||||
|
||||
Welcome to this open-source trading project. Here you will find powerful tools to enhance your trading journey. If you find this project useful, please consider starring ⭐, sharing, or donating to support further development!
|
||||
|
||||
---
|
||||
|
||||
**Support the project:**
|
||||
- Star this repository on GitHub
|
||||
- Share it with your trading friends
|
||||
- [Donate here](https://www.paypal.com/donate/?hosted_button_id=YOUR_BUTTON_ID) to help us grow!
|
||||
|
||||
---
|
||||

|
||||
|
||||
## Source Files
|
||||
- `demo_filecopy.mq5`
|
||||
|
||||
---
|
||||
> Made with ❤️ for the trading community.
|
||||
@@ -0,0 +1,75 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Demo_FileCopy.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 InpSrc="source.txt"; // source
|
||||
input string InpDst="destination.txt"; // copy
|
||||
input int InpEncodingType=FILE_ANSI; // ANSI=32 or UNICODE=64
|
||||
//+------------------------------------------------------------------+
|
||||
//| Script program start function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
//--- display the source contents (it must exist)
|
||||
if(!FileDisplay(InpSrc))
|
||||
return;
|
||||
//--- check if the copy file already exists (may not be created)
|
||||
if(!FileDisplay(InpDst))
|
||||
{
|
||||
//--- the copy file does not exist, copying without FILE_REWRITE flag (correct copying)
|
||||
if(FileCopy(InpSrc,0,InpDst,0))
|
||||
Print("File is copied!");
|
||||
else
|
||||
Print("File is not copied!");
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- the copy file already exists, try to copy without FILE_REWRITE flag (incorrect copying)
|
||||
if(FileCopy(InpSrc,0,InpDst,0))
|
||||
Print("File is copied!");
|
||||
else
|
||||
Print("File is not copied!");
|
||||
//--- InpDst file's contents remains the same
|
||||
FileDisplay(InpDst);
|
||||
//--- copy once more with FILE_REWRITE flag (correct copying if the file exists)
|
||||
if(FileCopy(InpSrc,0,InpDst,FILE_REWRITE))
|
||||
Print("File is copied!");
|
||||
else
|
||||
Print("File is not copied!");
|
||||
}
|
||||
//--- receive InpSrc file copy
|
||||
FileDisplay(InpDst);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Read the file contents |
|
||||
//+------------------------------------------------------------------+
|
||||
bool FileDisplay(const string file_name)
|
||||
{
|
||||
//--- reset the error value
|
||||
ResetLastError();
|
||||
//--- open the file
|
||||
int file_handle=FileOpen(file_name,FILE_READ|FILE_TXT|InpEncodingType);
|
||||
if(file_handle!=INVALID_HANDLE)
|
||||
{
|
||||
//--- display the file contents in the loop
|
||||
Print("+---------------------+");
|
||||
PrintFormat("File name = %s",file_name);
|
||||
while(!FileIsEnding(file_handle))
|
||||
Print(FileReadString(file_handle));
|
||||
Print("+---------------------+");
|
||||
//--- close the file
|
||||
FileClose(file_handle);
|
||||
return(true);
|
||||
}
|
||||
//--- failed to open the file
|
||||
PrintFormat("%s is not opened, error = %d",file_name,GetLastError());
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Reference in New Issue
Block a user