gpt4 book ai didi

batch-file - DOS 7 中的 SET 命令等效项

转载 作者:行者123 更新时间:2023-12-03 01:59:19 25 4
gpt4 key购买 nike

我有一台运行 DOS 7.10 的旧 MS DOS 计算机(ver 命令给出:windows 98 ver 4.10.2222)。我必须制作一个批处理脚本,基本上运行命令 10 次或任意次数。我尝试使用 for 命令,但它给了我 ILLEGAL Command For所以现在我有:

@ECHO off
SET COUNT=0

:MyLoop
IF "%COUNT%" == "10" GOTO EndLoop
ECHO %COUNT%
SET /a COUNT+=1
:EndLoop
ECHO done

但是,这给了我一个 0 的无限循环,就好像 set 命令不起作用一样。不过,该命令在 Windows 10 的 CMD 中确实有效。谁能建议我做错了什么?或者在 DOS 7 批处理文件中实现 for 循环的方法。

最佳答案

此批处理文件执行您所要求的操作。按原样,此示例最多可计数 123,但最多可计数 999(根据您的要求,可计数 1000 次)。如果您需要更多数字,只需添加相应的部分...

编辑 03/27/2018:按照评论中的建议修改代码

编辑 03/29/2018:第二次尝试

@echo off
if not "%1" == "" goto %1

set myself=%0

set count1=0

:MyLoop
if "%count3%%count2%%count1%" == "123" goto EndLoop
echo %count3%%count2%%count1%
call %myself% :incCount
goto MyLoop
:endLoop
echo Done
goto :EOF


:incCount
call %myself% :incDigit %count1%
set count1=%digit%
if %carry% == 0 goto endIncCount
call %myself% :incDigit %count2%
set count2=%digit%
if %carry% == 0 goto endIncCount
call %myself% :incDigit %count3%
set count3=%digit%
:endIncCount
goto :EOF

:incDigit digit
set carry=0
if not "%2" == "" goto next1
set digit=1
goto endIncDigit
:next1
if not %2 == 9 goto next2
set digit=0
set carry=1
goto endIncDigit
:next2
if %2 == 8 set digit=9
if %2 == 7 set digit=8
if %2 == 6 set digit=7
if %2 == 5 set digit=6
if %2 == 4 set digit=5
if %2 == 3 set digit=4
if %2 == 2 set digit=3
if %2 == 1 set digit=2
if %2 == 0 set digit=1
:endIncDigit

:EOF

编辑:添加了新方法

这种更简单的方法可以管理计数器中任意数量的数字,无需修改:

@echo off
if not "%1" == "" goto %1

set myself=%0

set count=0

:MyLoop
call %myself% :incCount
echo %printCnt%
if not "%printCnt%" == "123" goto MyLoop
echo Done
goto :EOF


:incCount
set newCnt=
set printCnt=
set carry=1
for %%a in (%count%) do call %myself% :incDigit %%a
set count=%newCnt%
if %carry% == 0 goto :EOF
set count=%count%,1
set printCnt=1%printCnt%
goto :EOF

:incDigit digit
set digit=%2
if %carry% == 0 goto endIncDigit
if not %2 == 9 goto next
set digit=0
goto endIncDigit
:next
if %2 == 8 set digit=9
if %2 == 7 set digit=8
if %2 == 6 set digit=7
if %2 == 5 set digit=6
if %2 == 4 set digit=5
if %2 == 3 set digit=4
if %2 == 2 set digit=3
if %2 == 1 set digit=2
if %2 == 0 set digit=1
set carry=0
:endIncDigit
set newCnt=%newCnt%,%digit%
set printCnt=%digit%%printCnt%

:EOF

关于batch-file - DOS 7 中的 SET 命令等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49513986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com