【问题标题】:Why this batch script not work fine?为什么这个批处理脚本不能正常工作?
【发布时间】:2013-08-28 02:47:18
【问题描述】:

这个脚本有什么问题?

@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 = 01, Input End = 08 或者 如果Input start = 01Input End = 09,不能正常工作并且没有下载excel文件。结果:

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

谁能解释一下?

【问题讨论】:

    标签: loops batch-file for-loop cmd


    【解决方案1】:

    前导零表示数字被解释为八进制。 0-7 无关紧要,但没有像八进制 8 或 9 这样的数字。您已经使用 2 个 SET 命令添加了前导 0,所以不要输入前导零。

    【讨论】:

      【解决方案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"
      )
      

      【讨论】:

        猜你喜欢
        • 2023-02-20
        • 2016-03-19
        • 1970-01-01
        • 1970-01-01
        • 2011-09-24
        • 2021-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多