Loading…

Data Folder Doctor

A FileOpen() failure inside some other script or EA reports a bare error code - 5002, 4103 - with nothing further to go on, and by the time it happens the run it was part of has usually already been interrupted. The three most common root causes are all things that can be checked in advance, in plain language, before they cause that failure somewhere important: the sandbox folder is not actually writable for some reason (permissions, a locked file, an odd install), the drive holding the data folder is nearly full, or a filename this catalogue's tools would create pushes the full path past Windows' historical 260-character limit once the data folder's own path is factored in. This script runs all three checks directly rather than inferring them. The write-permission check is a real probe, not a guess: it creates a small temporary file, writes to it, reads the content back, and deletes it, reporting exactly which of those four steps failed if one does. The path-length check is worth explaining, because it catches a mistake that is easy to make: a filename that looks perfectly short on its own screen can still overflow MAX_PATH once it is combined with a deeply-nested data folder path (which can happen after certain portable installs or profile migrations) - the script computes the actual worst-case combined length for a filename of a length you choose, rather than just checking the filename by itself. Notes and limitations The path-length check assumes Windows' historical 260-character MAX_PATH. Newer Windows versions can opt into longer paths via a system-wide policy setting, but that setting is not something MQL4 can detect from inside the sandbox, so this script always checks against the conservative 260-character limit rather than assuming the opt-in is active. Free disk space and permission checks reflect the state of the machine at the moment the script runs; both can change moments later from something entirely unrelated to this terminal (another program filling the disk, a backup tool briefly locking a folder). This is a diagnostic tool only - it does not free disk space, does not change any folder permission, and does not shorten any path. It reports what it finds so the underlying problem can be fixed by hand.

Script · MT5 · v1.0 · Free

About Data Folder Doctor

Data Folder Doctor is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Min free disk mb, Check common folder and Longest filename check. MQL source code included.

Files in the download: DataFolderDoctor.ex5, DataFolderDoctor.mq5, DataFolderDoctor.txt.

Settings

SettingDefaultWhat it does
Min free disk mb500Minimum acceptable free disk space, in MB
Check common foldertrueAlso probe the shared Common\Files folder
Longest filename check64Longest filename this catalogue's tools might create, for the path-length check

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria