Loops 为什么这个批处理脚本不能正常工作?
这个脚本有什么问题Loops 为什么这个批处理脚本不能正常工作?,loops,batch-file,for-loop,cmd,Loops,Batch File,For Loop,Cmd,这个脚本有什么问题 @echo off SETLOCAL ENABLEEXTENSIONS SETLOCAL ENABLEDELAYEDEXPANSION set /P start= Input start : %=% set /P end= Input End : %=% for /l %%i IN (%start%,1,%end%) DO ( set num=0%%i set num=!num:~-2! echo wget "http://portal/exce
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set /P start= Input start : %=%
set /P end= Input End : %=%
for /l %%i IN (%start%,1,%end%) DO (
set num=0%%i
set num=!num:~-2!
echo wget "http://portal/excel!num!.xls"
)
pause
如果Input start=01
,Input End=06
,工作正常并下载excel文件。结果:
Input start : 01
Input End : 12
wget "http://portal/excel01.xls"
wget "http://portal/excel02.xls"
wget "http://portal/excel03.xls"
wget "http://portal/excel04.xls"
wget "http://portal/excel05.xls"
wget "http://portal/excel06.xls"
wget "http://portal/excel07.xls"
wget "http://portal/excel08.xls"
wget "http://portal/excel09.xls"
wget "http://portal/excel10.xls"
Press any key to continue . . .
Input start : 01
Input End : 08
Press any key to continue . . .
但是如果Input start=01
,Input End=08
或
如果Input start=01
,Input End=09
,则工作不正常,excel文件未下载。结果:
Input start : 01
Input End : 12
wget "http://portal/excel01.xls"
wget "http://portal/excel02.xls"
wget "http://portal/excel03.xls"
wget "http://portal/excel04.xls"
wget "http://portal/excel05.xls"
wget "http://portal/excel06.xls"
wget "http://portal/excel07.xls"
wget "http://portal/excel08.xls"
wget "http://portal/excel09.xls"
wget "http://portal/excel10.xls"
Press any key to continue . . .
Input start : 01
Input End : 08
Press any key to continue . . .
有人能解释一下吗?前导零表示数字被解释为八进制。0-7没关系,但没有八进制8或9这样的数字。您已经在使用2个SET命令添加前导0,因此不要输入前导零。前导零表示数字被解释为八进制。0-7没关系,但没有八进制8或9这样的数字。您已经在使用2个SET命令添加前导零,因此不要输入前导零。这是一个解决方法:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set start=101
set end=199
for /l %%i IN (%start%,1,%end%) DO (
set num=!num:~-2!
echo wget "http://portal/excel!num!.xls"
)
这是一个解决方法:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set start=101
set end=199
for /l %%i IN (%start%,1,%end%) DO (
set num=!num:~-2!
echo wget "http://portal/excel!num!.xls"
)