Powershell copy with wildcard

77 views Asked by At

The following works fine. Copy-Item -Path C:\Users\Administrator\Desktop\EA\MT4\EA_bot.ex4 -Destination C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\0C2BFA140CA8FBEFEDCADDDEDD61AA24\MQL4\Experts\

However I want to do this for all directories that have the following wild carded, there are many instances: C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\*\MQL4\Experts\

Thank you,

I used * like in linux, that doesn't work in PS

2

There are 2 answers

0
Scott Bowden On BEST ANSWER

I actually took this further, which might help others. This copies all *.ex4 or all *.ex5 files to ALL instances of MT4 or MT5 at one time with two commands. It copies from my local computer to the VPS servers; I just save the files to MT4 or MT5 locally. I changed the paths just for the fun of it; don't use your desktop, as Microsoft syncs that to their cloud, and it just makes stuff run slow.

Get-ChildItem -Path "C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\*\MQL4\Experts" -Directory | ForEach-Object { Copy-Item -Path "\\tsclient\C\NOTYOURDESKTOPMICROSOFT\MT4\*.ex4" -Destination $_.FullName }
Get-ChildItem -Path "C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\*\MQL5\Experts" -Directory | ForEach-Object { Copy-Item -Path "\\tsclient\C\NOTYOURDESKTOPMICROSOFT\MT5\*.ex5" -Destination $_.FullName }

enter image description here

1
Martin Iszac On

Use Get-ChildItem to loop over all the directories. You can do this in a one-liner.

Get-ChildItem -Path "C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\*\MQL4\Experts\" -Directory | ForEach-Object { Copy-Item -Path "C:\Users\Administrator\Desktop\EA\MT4\EA_bot.ex4" -Destination $_.FullName }

This will copy the EA_bot.exe to MQL4\Experts\ under any directory in C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\