【发布时间】:2017-03-31 20:24:15
【问题描述】:
我在命令外壳代码中有以下代码。
SET MYdir=%NewPath%\%CUST%\SuppliesTypes
SET "MYsCount=1"
SET /p MYsCount="Number of MYs in project? (default: %MYSCount%): "
for /L %%a in (1,1,%MYsCount%) do (
SET /p MYNums="Enter %%a MY Number: "
call md "%MYdir%\MY_%%MYNums%%"
)
SET "MYsCount="
但是,我正在将我的代码从 CMD 转换为 PowerShell。我不完全理解转换过来的正确方法。这可能是它应该如何完成的,但它不工作,因为它只是跳过。
SET MYdir=%NewPath%\%CUST%\Product
SET "MYsCount=1"
SET /p MYsCount="Number of MYs in project? (default: %MYSCount%): "
For ($MYsCount = 1; $MYsCount -eq 10; $MYsCount++){
SET /p MyNums="Enter %%a Product Numbers: "
CALL MD "%MYdir%\%CUST%\Product_%%"
}
SET "$MYsCount="
我查看了以下网站和文章:
- PowerShell Basics: Programming With Loops(帮助验证)
- How to do a forloop in a Django template?(没有真正帮助)
- Windows PowerShell Cookbook, 3rd Edition (第170页)
我在 While 循环中运行此代码。
感谢您的帮助!
【问题讨论】:
-
您使用
$MYsCount -eq 10作为条件。它应该是$MYsCount -le 10(小于或等于)。仅供参考,powershell 示例中的其余代码(循环除外)不是 powershell 代码...
标签: windows powershell for-loop while-loop counter