所以我要做的就是创建一个动态变量,最终成为从网站下载的最新文件。在我的示例中,我尝试下载" downloads.informais.com/updates/psn_basic_sqlite_r4_20170531.exe"通过自动化流程。 r是修订号,日期是日期。所以这就是我现在所拥有的:
@echo off
::http://downloads.informais.com/updates/psn_basic_sqlite_r4_20170531.exe
echo Dates > Dates.txt
::Get Variables
set num=11
set /a "num=num-1"
::: Begin set date
for /f "tokens=1-4 delims=/-. " %%i in ('date /t') do (call :set_date %%i %%j %%k %%l)
goto :end_set_date
:set_date
if "%1:~0,1%" gtr "9" shift
for /f "skip=1 tokens=2-4 delims=(-)" %%m in ('echo,^|date') do (set %%m=%1&set %%n=%2&set %%o=%3)
goto :eof
:end_set_date
::: End set date
set PSN=psn_basic_sqlite_r%num%_%yy%%mm%%dd%
set download=http://downloads.informais.com/updates/%PSN%.exe
GOTO TryPSNdownload
::Get the latest download
:TryPSNdownload
::Fix Days
if %dd%==9 set dd=09
if %dd%==8 set dd=08
if %dd%==7 set dd=07
if %dd%==6 set dd=06
if %dd%==5 set dd=05
if %dd%==4 set dd=04
if %dd%==3 set dd=03
if %dd%==2 set dd=02
if %dd%==1 set dd=01
set /a "num=num-1"
set PSN=psn_basic_sqlite_r%num%_%yy%%mm%%dd%
set download=http://downloads.informais.com/updates/%PSN%.exe
echo %download% >> Dates.txt
if exist "%download%" (
GOTO Download
) else (
::Fix Month
if %mm%==9 set mm=09
if %mm%==8 set mm=08
if %mm%==7 set mm=07
if %mm%==6 set mm=06
if %mm%==5 set mm=05
if %mm%==4 set mm=04
if %mm%==3 set mm=03
if %mm%==2 set mm=02
if %mm%==1 set mm=01
if %mm%==0 set mm=12
if %dd%==0 set dd=33
if %num%==0 set /a "dd=dd-1"
if %dd%==0 set /a "mm=mm-1"
if %num%==0 set num=11
GOTO TryPSNdownload
)
:Download
Echo %download%
pause
这是将%download%变量输出到txt文件,所以你可以看到我在说什么,但它是这样的:
http://downloads.informais.com/updates/psn_basic_sqlite_r0_20170609.exe
http://downloads.informais.com/updates/psn_basic_sqlite_r10_201706-1.exe
http://downloads.informais.com/updates/psn_basic_sqlite_r9_201706-1.exe
我觉得这是一个操作类型的事情,但我无法弄明白。我把这个地方添加到"修复" dd变量,为了保持两位数,在它之前它会正确倒计时,除了它不会包括单个数字前的零。有关如何解决的任何建议吗?
答案 0 :(得分:0)
我能够通过更改PSN变量来包含" 0"在%dd%之前,如果" dd"小于10,并保持其他操作相同,现在它的工作原理: - )
@echo off
::http://downloads.informais.com/updates/psn_basic_sqlite_r4_20170531.exe
echo Dates > Dates.txt
::Get Variables
set num=11
set /a "num=num-1"
::: Begin set date
for /f "tokens=1-4 delims=/-. " %%i in ('date /t') do (call :set_date %%i %%j %%k %%l)
goto :end_set_date
:set_date
if "%1:~0,1%" gtr "9" shift
for /f "skip=1 tokens=2-4 delims=(-)" %%m in ('echo,^|date') do (set %%m=%1&set %%n=%2&set %%o=%3)
goto :eof
:end_set_date
::: End set date
set PSN=psn_basic_sqlite_r%num%_%yy%%mm%%dd%
set download=http://downloads.informais.com/updates/%PSN%.exe
GOTO TryPSNdownload
::Get the latest download
:TryPSNdownload
set /a "num=num-1"
::Fix Days
if %dd% LSS 10 (set PSN=psn_basic_sqlite_r%num%_%yy%%mm%0%dd%) else (set PSN=psn_basic_sqlite_r%num%_%yy%%mm%%dd%)
set download=http://downloads.informais.com/updates/%PSN%.exe
echo %download% >> Dates.txt
if exist "%download%" (
GOTO Download
) else (
::Fix Month
if %mm%==9 set mm=09
if %mm%==8 set mm=08
if %mm%==7 set mm=07
if %mm%==6 set mm=06
if %mm%==5 set mm=05
if %mm%==4 set mm=04
if %mm%==3 set mm=03
if %mm%==2 set mm=02
if %mm%==1 set mm=01
if %mm%==0 set mm=12
if %num%==0 set /a "dd=dd-1"
if %dd%==0 set /a "mm=mm-1"
if %dd%==0 set dd=33
if %num%==0 set num=11
GOTO TryPSNdownload
)
:Download
Echo %download%
pause