Skip to content

Instantly share code, notes, and snippets.

@bukowa
Last active September 2, 2023 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukowa/f5c70955c9c2a427db3644b2f7409000 to your computer and use it in GitHub Desktop.
Save bukowa/f5c70955c9c2a427db3644b2f7409000 to your computer and use it in GitHub Desktop.
mt4 sync copy
import os
import shutil
from pathlib import Path
MT4_DIR = Path("C:\\Users\\buk\\AppData\\Roaming\\MetaQuotes\\Terminal\\")
MT4_MASTER = MT4_DIR / '2C68BEE3A904BDCEE3EEF5A5A77EC162'
BACKUP_DIR = MT4_DIR / 'backup'
CACHE_FILE = 'mqlcache.dat'
MT4_SLAVES = [
MT4_DIR / 'E014E927B1217F5A561E0813A1C319F3'
]
COPY_DIRS = [
'templates',
'MQL4/Experts',
'MQL4/Files',
'MQL4/Include',
'MQL4/Indicators',
'MQL4/Libraries',
'MQL4/Presets',
'MQL4/Scripts',
]
def force_cp(cf, ct):
try:
shutil.rmtree(ct)
except FileNotFoundError:
pass
shutil.copytree(cf, ct)
if __name__ == '__main__':
for subdir in COPY_DIRS:
cfrom = MT4_MASTER / subdir
force_cp(cfrom, BACKUP_DIR/subdir)
for slave in MT4_SLAVES:
cto = slave / subdir
print(cfrom)
print(cto)
force_cp(cfrom, cto)
try:
os.remove(cto / CACHE_FILE)
except FileNotFoundError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment