Board logo

标题: [求助]for循环嵌套,数字与文件对应问题 [打印本页]

作者: greenworld     时间: 2007-9-24 22:01    标题: [求助]for循环嵌套,数字与文件对应问题

在某个文件夹了有多个.bat文件,为了简单起见,现在假设是2个(实际是多个的),偶写了一下程序
set /p n=请输入一个正整数:
for /f %%i in ('dir /b j:\cd\*.bat') do (
for /l %%b in (1,1,%n%) do (
echo Shell%%bCaption=>>SETUP.INI
echo Shell%%bCommand=%%i>>SETUP.INI
echo.>>SETUP.INI
)
)
pause

例如我输入 3 结果SETUP.INI里面的内容是
Shell1Caption=
Shell1Command=WSXP.BAT

Shell2Caption=
Shell2Command=WSXP.BAT

Shell3Caption=
Shell3Command=WSXP.BAT

Shell1Caption=
Shell1Command=WSXZ.BAT

Shell2Caption=
Shell2Command=WSXZ.BAT

Shell3Caption=
Shell3Command=WSXZ.BAT

但我想要的结果是
Shell1Caption=
Shell1Command=WSXP.BAT

Shell2Caption=
Shell2Command=WSXZ.BAT

Shell3Caption=
Shell3Command=
请问怎样才能得到预期的结果呢??希望高人解答一下,多谢了
作者: lxmxn     时间: 2007-9-25 01:02
ShellCommand= 后面是不是接的三个不同的批处理文件名?
作者: greenworld     时间: 2007-9-25 19:36


  Quote:
Originally posted by lxmxn at 2007-9-25 01:02 AM:
ShellCommand= 后面是不是接的三个不同的批处理文件名?

是的,就是ShellCommand=后面对应不同的bat文件,望老大出手了....多谢
作者: lxmxn     时间: 2007-9-25 21:01

@echo off &SetLocal EnableDelayedExpansion

set /p number=请输入数字:
if not defined number exit/b
for /F "delims=" %%a in ('dir /s/b/a-d j:\cd\*.bat') do (
    set /a temp+=1
    (
        echo Shell!temp!Caption=
            echo Shell!temp!Command=%%a
        echo\
    )>>SETUP.INI
    if !temp! equ %number% goto :eof
)
有时间多看看for相关的教程.

[ Last edited by lxmxn on 2007-9-25 at 09:16 PM ]