[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [已解决]批处理命令for提取2行后,怎么给每行设变量?

本帖最后由 lantern 于 2014-5-23 01:29 编辑

想弄个bat处理Virtualbox安装包
  1. @echo off
  2. REM 获取最新版本号
  3. wget -N http://download.virtualbox.org/virtualbox/LATEST.TXT
  4. for /f %%i in (LATEST.TXT) do (set latest=%%i)
  5. REM 获取最新版本号目录
  6. echo http://download.virtualbox.org/virtualbox/%latest%  >dl.txt
  7. REM .vbox-extpack也可直接下载了
  8. echo http://download.virtualbox.org/virtualbox/%latest%/Oracle_VM_VirtualBox_Extension_Pack-%latest%.vbox-extpack >>dl.txt
  9. wget -N -i dl.txt
  10. REM .exe包含小版本号,不能直接下载
  11. REM 获取exe文件名
  12. for /f "delims=<,> tokens=3 skip=4" %%i in (index.html) do (echo %%i>>ddd.txt)
  13. findstr "exe" ddd.txt>dddd.txt
  14. REM 去除行首空格
  15. for /f %%i in (dddd.txt) do (set exe=%%i)
  16. REM 下载exe
  17. echo http://download.virtualbox.org/virtualbox/%latest%/%exe% >dl.txt
  18. wget -N -i dl.txt
  19. REM 解压VirtualBox-Version-Win.exe
  20. %exe% --extract --path VirtualBox --silent
  21. REM 解压Oracle_VM_VirtualBox_Extension_Pack-Version.vbox-extpack
  22. 7z x *.vbox-extpack -oVirtualBox
  23. 7z x VirtualBox\Oracle_VM_VirtualBox_Extension_Pack-* -oVirtualBox\ExtensionPacks
  24. for /f "tokens=4" %%i in ('dir VirtualBox\*.msi') do (echo %%i>>a.txt | findstr "msi" a.txt>b.txt)
  25. for /f "tokens=*" %%i in (b.txt) do (set msi=%%i)
  26. msiexec /a VirtualBox\%msi%  /qb TARGETDIR="%CD%\VirtualBox\x86"
  27. msiexec /a VirtualBox\%msi%  /qb TARGETDIR="%CD%\VirtualBox\x64"
  28. del *.txt *.html
  29. pause
复制代码
VirtualBox-4.3.12-93733-Win.exe解压到VirtualBox目录后有3个文件:
common.cab
VirtualBox-4.3.12-r93733-MultiArch_amd64.msi
VirtualBox-4.3.12-r93733-MultiArch_x86.msi
最后一步不会弄了,msiexec两行都是解压x86的msi...
怎么才能分别执行x86和x64?谢谢
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

  1. @echo off
  2. setlocal enableDelayedExpansion
  3. REM 获取最新版本号setlocal enableDelayedExpansion
  4. wget -N http://download.virtualbox.org/virtualbox/LATEST.TXT
  5. for /f %%i in (LATEST.TXT) do (set latest=%%i)
  6. REM 获取最新版本号目录
  7. echo http://download.virtualbox.org/virtualbox/%latest%  >dl.txt
  8. REM .vbox-extpack也可直接下载了
  9. echo http://download.virtualbox.org/virtualbox/%latest%/Oracle_VM_VirtualBox_Extension_Pack-%latest%.vbox-extpack >>dl.txt
  10. wget -N -i dl.txt
  11. REM .exe包含小版本号,不能直接下载
  12. REM 获取exe文件名
  13. for /f "delims=<,> tokens=3 skip=4" %%i in (index.html) do (echo %%i>>ddd.txt)
  14. findstr "exe" ddd.txt>dddd.txt
  15. for /f %%i in (dddd.txt) do (set exe=%%i)
  16. REM 下载exe
  17. echo http://download.virtualbox.org/virtualbox/%latest%/%exe% >dl.txt
  18. wget -N -i dl.txt
  19. REM 解压VirtualBox-Version-Win.exe
  20. %exe% --extract --path VirtualBox --silent
  21. REM 解压Oracle_VM_VirtualBox_Extension_Pack-Version.vbox-extpack
  22. 7z x *.vbox-extpack -oVirtualBox
  23. 7z x VirtualBox\Oracle_VM_VirtualBox_Extension_Pack-* -oVirtualBox\ExtensionPacks
  24. for %%i in (64 86) do (
  25.     for %%j in (VirtualBox\*%%i.msi) do (
  26.         msiexec /a %%j /qb TARGETDIR="%CD%\VirtualBox\x%%i"
  27.     )
  28. )
  29. del *.txt *.html
  30. pause
复制代码
1

评分人数

TOP

找到一个解决方案:http://bathome.l3.wuyou.com/viewthread.php?tid=11976
各位前辈帮忙优化一下吧,谢谢
  1. @echo off
  2. setlocal enableDelayedExpansion
  3. REM 获取最新版本号setlocal enableDelayedExpansion
  4. wget -N http://download.virtualbox.org/virtualbox/LATEST.TXT
  5. for /f %%i in (LATEST.TXT) do (set latest=%%i)
  6. REM 获取最新版本号目录
  7. echo http://download.virtualbox.org/virtualbox/%latest%  >dl.txt
  8. REM .vbox-extpack也可直接下载了
  9. echo http://download.virtualbox.org/virtualbox/%latest%/Oracle_VM_VirtualBox_Extension_Pack-%latest%.vbox-extpack >>dl.txt
  10. wget -N -i dl.txt
  11. REM .exe包含小版本号,不能直接下载
  12. REM 获取exe文件名
  13. for /f "delims=<,> tokens=3 skip=4" %%i in (index.html) do (echo %%i>>ddd.txt)
  14. findstr "exe" ddd.txt>dddd.txt
  15. for /f %%i in (dddd.txt) do (set exe=%%i)
  16. REM 下载exe
  17. echo http://download.virtualbox.org/virtualbox/%latest%/%exe% >dl.txt
  18. wget -N -i dl.txt
  19. REM 解压VirtualBox-Version-Win.exe
  20. %exe% --extract --path VirtualBox --silent
  21. REM 解压Oracle_VM_VirtualBox_Extension_Pack-Version.vbox-extpack
  22. 7z x *.vbox-extpack -oVirtualBox
  23. 7z x VirtualBox\Oracle_VM_VirtualBox_Extension_Pack-* -oVirtualBox\ExtensionPacks
  24. for /f "tokens=4" %%i in ('dir VirtualBox\*.msi') do (echo %%i>>a.txt | findstr "msi" a.txt>b.txt)
  25. for /f "tokens=*" %%i in (b.txt) do (
  26. set /a b+=1
  27. echo %%i>!b!.txt)
  28. set /p msi=<1.txt
  29. msiexec /a VirtualBox\%msi%  /qb TARGETDIR="%CD%\VirtualBox\x64"
  30. set /p msi=<2.txt
  31. msiexec /a VirtualBox\%msi%  /qb TARGETDIR="%CD%\VirtualBox\x86"
  32. del *.txt *.html
  33. pause
复制代码

TOP

返回列表