cmd.exe没有递增for循环中的数字

时间:2015-03-26 13:34:37

标签: windows batch-file cmd

我已经在圈子里走了一个多小时了,有人告诉我为什么这不起作用了吗?

我需要创建一个文件夹数组,并使用该数组触发robocopy命令

@echo off
setlocal EnableDelayedExpansion
set str=%USERPROFILE%
set server=\\poppy
call set mod=%%str:C:=%server%%%
if not exist "%mod%" mkdir %mod%
set list= %mod%\Documents %mod%\Downloads
set counter=0
(for %%a in (%list%) do (
    echo.%%a
    set counter=counter+1
    echo.%counter%
))
pause

无论我尝试什么,我都无法增加柜台: - (

1 个答案:

答案 0 :(得分:3)

@echo off
setlocal EnableDelayedExpansion
set "str=%USERPROFILE%"
set "server=\\poppy"
call set "mod=%%str:C:=%server%%%"
if not exist "%mod%" mkdir %mod%
set "list= %mod%\Documents %mod%\Downloads"
set counter=0
setlocal enableDelayedExpansion
(for %%a in (%list%) do (
    echo.%%a
    set /a counter=counter+1
    echo.!counter!
))
endlocal
pause

有关详细信息,请查看此内容 - http://blogs.msdn.com/b/oldnewthing/archive/2006/08/23/714650.aspx

对于SET的算术,您需要/A切换。