2013-08-28 308 views
0

这个脚本有什么问题?为什么这个批处理脚本不能正常工作?

@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 = 01Input 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 = 01Input End = 08或 如果Input start = 01Input End = 09,不做工精细和Excel文件未下载。结果:

Input start : 01 
Input End : 08 
Press any key to continue . . . 

任何人都可以提供一些解释吗?

回答

3

前导零表示数字被解释为八进制数。 0-7无关紧要,但不存在八进制8或9之类的数字。您已经使用2 SET命令添加前导0,因此不要输入前导零。

+0

感谢ü非常 – flyingbird013

2

这是一种解决方法:

@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" 
) 
相关问题