Run a command using PowerShell on each directory with an assumed path component -
i found this question, very similar want couldn't work.
i want run process.exe on each subdirectory's xml directory of c:\toprocess. if did hand, first 6 of 50 or commands this:
process.exe -switch1 -switch2 -i "c:\toprocess\abx\xml" -o "c:\processed\abx\xml" process.exe -switch1 -switch2 -i "c:\toprocess\dez\xml" -o "c:\processed\dez\xml" process.exe -switch1 -switch2 -i "c:\toprocess\ghm\xml" -o "c:\processed\ghm\xml" process.exe -switch1 -switch2 -i "c:\toprocess\jkq\xml" -o "c:\processed\jkq\xml" process.exe -switch1 -switch2 -i "c:\toprocess\mn0\xml" -o "c:\processed\mn0\xml" process.exe -switch1 -switch2 -i "c:\toprocess\pq2\xml" -o "c:\processed\pq2\xml"
but before running commands, have this, because target folders not yet exist:
md "c:\processed\abx" md "c:\processed\dez" md "c:\processed\ghm" md "c:\processed\jkq" md "c:\processed\mn0" md "c:\processed\pq2" md "c:\processed\abx\xml" md "c:\processed\dez\xml" md "c:\processed\ghm\xml" md "c:\processed\jkq\xml" md "c:\processed\mn0\xml" md "c:\processed\pq2\xml"
so, there way in couple commands?
this should work. create each of destination directories if don't exist , run process.exe on each.
get-childitem c:\toprocess\*\xml | foreach-object { $newpath = $_.fullname.replace("toprocess","processed"); new-item $newpath -itemtype directory -erroraction silentlycontinue; .\process.exe -switch1 -switch2 -i $_.fullname -o $newpath; }
update: added .\ before process following comment
Comments
Post a Comment