本帖最后由 daols 于 2012-12-16 14:06 编辑
- @echo off
- ::setlocal enableextensions
- ::setlocal enabledelayedexpansion
- set wgetex=%~dp0wget.exe
- set autodir="%tmp%"
- set logfile="%tmp%\wgetx.log"
- set wget="%ComSpec%" /k %wgetex% --no-check-certificate -c -S -t 0 -U "Opera/9"
- if not exist "%wgetex%" (echo Error: "%wgetex%" not found.&&pause&&goto end)
- if /I [%1]==[] (goto usage) else if /I [%1]==[/?] (goto usage) else if /I [%1]==[--help] (goto usage)
- if exist "%windir%\tray.exe" (set wget="%windir%\tray.exe" %wget%)
- if /I [%2] NEQ [] (set wget=%wget% %~3 %~4 %~5 %~6 %~7 %~8 %~9 -P %2) else (set wget=%wget% %~3 %~4 %~5 %~6 %~7 %~8 %~9 -P %autodir%)
- if exist %1 (set wget=%wget% -i %1) else (set wget=%wget% %1)
- if defined logfile (echo %date:~0,10% # %time%>>%logfile%&&echo line: %0 %*>>%logfile%&&echo exec: start "%0" %wget%>>%logfile%&&echo.>>%logfile%)
- start "%0" %wget%
- ::pause
- goto end
-
- :usage
- echo Usage :
- echo %0 "$URL" [Save to %autodir% by default]
- echo %0 "$URL" "$SavePath"
- echo %0 "$UrlListFile.txt" "$SavePath"
- echo %0 "$URL" "$SavePath" "--referer=$URL -r -p -np -k"
- echo note:
- echo 1.前两个参数默认为 "url[或url列表文件]路径" 和 "下载位置",
- echo 如果有其他[最多9个]参数, 会自动追加传递给wget
- echo [比如: [wgetx . . --help] 会自动调用wget帮助],
- echo 2.内部有[=]或[^"]等保留字的参数外部需加双引号,
- echo %%3及其以后的参数会被自动脱掉最外层双引号,
- echo 这样可以绕过9参数上限并不受参数中 [=] 号的影响.
- echo 3.参数内部有多个 [=] 号时不能同时存在双引号,
- echo 且参数中不能有空格, 同时要在整个参数外部加双引号.
- echo 4.旧版本 wget-1.10.2 支持--no-check-certificate, 新版不支持,
- echo 5.在使用 [start "%ComSpec%" ...] 命令的脚本中,
- echo 各版本wget.exe路径外都不可带引号, 会报找不到文件错误,
- echo 所以程序路径中不能有空格和中文.
- echo demo:
- echo %wgetex% --no-check-certificate -c -S -t 0 -U "Opera/9" -P "%autodir%" -i "$UrlList.txt"
- echo %wgetex% --no-check-certificate -c -S -t 0 -U "Opera/9" -P "%autodir%" "http://users.ugent.be/~bpuype/wget/wget.exe"
- echo %wgetex% --no-check-certificate -c -S -t 7 -U "Opera/9" -P "%autodir%" -r -p -np -k "http://docs.gimp.org/2.2/zh_CN/"
- echo.
- pause
-
- :end
- ::# 1. IF [/I] string1 compare-op[EQU/NEQ...] string2 中的 string1 里有 [=] 号的时候 string1 外不能有双引号, 否则会忽略 /I 以及 compare-op 运算, 并优先被当作 IF string1==string2 命令处理而报错. 可以用 [ ] 括号来代替引号, 如: if /I [%1] EQU [] ...
- ::# 2. 用 %n 传参时如果参数中有一个 [=] 号并带双引号, 须在整个参数外用双引号, 处理时用 %~n 来脱引号, 否则参数会被 = 分割成两个, 如 [--referer="$URL" -r -p -np -k] 五个参数可用 ["--referer="$URL" -r -p -np -k"] 合并成一个来传入. 这样可以绕过9参数上限并不受参数中 [=] 号的影响.
- ::# 目前的问题是: 像 [--referer="$URL/?a=b"] 这样带更多 [=] 号和引号的参数仍没有方法正确传递.
- ::# 测试: wgetx "$URL/?1=a" "2=b" "--referer="$URL/?3=c"" "-r -p -np -k"
- ::# 显示: start "wgetx" "C:\WIN2003\tray.exe" "C:\WIN2003\system32\cmd.exe" /k C:\WIN2003\wget.exe --no-check-certificate -c -S -t 0 -U "Opera/9" --referer="$URL/?3 c"" -r -p -np -k -P "2=b") else (set wget="C:\WIN2003\tray.exe" "C:\WIN2003\system32\cmd.exe" /k C:\WIN2003\wget.exe --no-check-certificate -c -S -t 0 -U "Opera/9" --referer="$URL/?3 c"" -r -p -np -k -P "B:\TEMP" "$URL/?1=a"
- ::# 也就是说参数内部有多个 [=] 时不能同时存在双引号, 且参数中不能有空格, 同时要在整个参数外部加双引号.
复制代码
|