-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsort_root.ps1
More file actions
46 lines (37 loc) · 1.67 KB
/
Copy pathsort_root.ps1
File metadata and controls
46 lines (37 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$rootDir = "D:\code\ex5-backtest"
$eas = "$rootDir\EAs"
$indis = "$rootDir\Indicators"
$utils = "$rootDir\Utilities"
$others = "$rootDir\Others"
# Create directories if not exist
$eas, $indis, $utils, $others | ForEach-Object {
if (-not (Test-Path $_)) { New-Item -ItemType Directory -Path $_ | Out-Null }
}
function Move-MqlPair ($BaseName, $DestDir) {
if (Test-Path "$rootDir\$BaseName.mq5") { Move-Item -Path "$rootDir\$BaseName.mq5" -Destination $DestDir -Force }
if (Test-Path "$rootDir\$BaseName.ex5") { Move-Item -Path "$rootDir\$BaseName.ex5" -Destination $DestDir -Force }
}
# 1. Categorize by parsing .mq5 files in the root dir
Get-ChildItem -Path $rootDir -Filter *.mq5 -File | ForEach-Object {
$content = Get-Content $_.FullName -TotalCount 200 -ErrorAction SilentlyContinue
$isIndicator = $content -match "#property\s+indicator_"
$isEA = $content -match "OnTick\s*\("
$isScript = $content -match "OnStart\s*\("
$dest = $others
if ($isIndicator) { $dest = $indis }
elseif ($isEA) { $dest = $eas }
elseif ($isScript) { $dest = $utils }
Move-MqlPair $_.BaseName $dest
}
# 2. Categorize remaining .ex5 files in root dir by heuristics
Get-ChildItem -Path $rootDir -Filter *.ex5 -File | ForEach-Object {
$name = $_.BaseName.ToLower()
$dest = $others
if ($name -match "indicator|indi|channel|band|oscillator|macd|rsi|sma|ema") {
$dest = $indis
} elseif ($name -match "ea|bot|auto|trade|manager|close|grid|hedge|mgr") {
if ($name -match "close all") { $dest = $utils } else { $dest = $eas }
}
Move-Item -Path $_.FullName -Destination $dest -Force
}
Write-Output "Root directory sorting complete."