标题: [文本处理] [已解决]求助批处理FOR提取数据加入skip就无效 [打印本页]
作者: yakeyun 时间: 2022-7-17 14:11 标题: [已解决]求助批处理FOR提取数据加入skip就无效
这边需要对GPU-Z获取到的显卡信息做提取,如果加入skip命令后,就无法获取到数据,删除后就可以正常提取。
请问在不提取数据到新文档的前提下,有办法可以直接通过代码调整获取第二块显卡的数据信息吗?- @echo off & setlocal EnableDelayedExpansion
- @cd /d "%~dp0"
-
- for /f "skip=54 tokens=*" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do echo %%a
- pause
-
- for /f "skip=54 delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subsysid=%%c)
- echo %subsysid%
-
- pause>nul
- echo.
- pause
复制代码
文件提取地址:https://sanli.lanzoub.com/ieqqF07y3u9e
作者: flashercs 时间: 2022-7-17 14:50
- @echo off & setlocal EnableDelayedExpansion
- @cd /d "%~dp0"
-
- for /f "skip=1 tokens=*" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do echo %%a
- pause
-
- for /f "skip=1 tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set subsysid=%%c
- )
- echo %subsysid%
-
- pause>nul
- echo.
- pause
复制代码
作者: yakeyun 时间: 2022-7-17 15:48
回复 2# flashercs
54行之前是第一个显卡的数据信息,54行以后是第二个显卡的数据。
已知第一个显卡的现在需要把两个显卡的信息分别获取出来。
完整代码如下:- @echo off
- @cd /d "%~dp0"
- if exist gpuz.xml (del gpuz.xml)
- if exist ")" (del ")")
- call GPU-Z.exe -dump GPUZ.xml
- setlocal EnableDelayedExpansion
-
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<gpuname>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set gpuname=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<vendorid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set vendorid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<deviceid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set deviceid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<subvendorid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subvendorid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subsysid=%%c)
-
- echo %vendorid% %deviceid%-%subvendorid% %subsysid%
- echo %gpuname%
- ::10400 Comet Lake GT2
- if "%gpuname%"=="Intel Xe" (start /min "" ".\DG1\DVrun.bat" & Goto End)
- if "%gpuname%"=="Arc Alchemist" (start /min "" ".\A380\DVrun.bat" & Goto End)
- if "%gpuname%"=="Alder Lake" (start /min "" ".\Intel_Video\DvRun.bat" & Goto End)
- if "%vendorid%"=="8086" (start /min "" ".\Intel_Video\DvRun.bat" & Goto End)
-
- if "%vendorid%"=="1002" (echo 我是AMD显卡 & start /min "" ".\AMD580\DvRun.bat" & Goto End)
-
- if "%gpuname%"=="GK208" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GK208B" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GF119" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GF108" (echo 我是NVIDIAGT730显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GK208B" (echo 我是NVIDIAGT730显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
-
- ::T600 T400 T1000
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB1-10DE 1488" (echo 我是NVIDIAT600显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB2-10DE 1489" (echo 我是NVIDIAT400显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%gpuname%"=="GA106" (echo 我是NVIDIAA2000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%gpuname%"=="GP106" (echo 我是NVIDIAP2000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- ::P1000 P620 P400
- if "%gpuname%"=="GP107" (echo 我是NVIDIAP620显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
-
- if "%vendorid%"=="10DE" (echo 我是NVIDIA游戏显卡 & start /min "" ".\NV3050\DvRun.bat" & Goto End)
- :End
- if exist gpuz.xml (del gpuz.xml)
- if exist ")" (del ")")
- exit
复制代码
作者: flashercs 时间: 2022-7-17 16:30
- @echo off
- @cd /d "%~dp0"
- if exist gpuz.xml (del gpuz.xml)
- if exist ")" (del ")")
- call GPU-Z.exe -dump GPUZ.xml
- setlocal EnableDelayedExpansion
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<gpuname>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set gpuname!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<vendorid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set vendorid!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<deviceid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set deviceid!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<subvendorid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set subvendorid!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set subsysid!n!=%%c
- set /a n+=1
- )
-
- echo %vendorid1% %deviceid1%-%subvendorid1% %subsysid1%
- echo %vendorid2% %deviceid2%-%subvendorid2% %subsysid2%
复制代码
作者: yakeyun 时间: 2022-7-17 17:56
回复 4# flashercs
谢谢大佬,可以正常取值。这个代码主要是用来安装显卡驱动的,由于技嘉主板CPU带核显的情况下,会显示2个显卡选项,所以之前的代码默认只打了核显驱动,没有打独显。
我这边用创建第三方文件的方法,也得到了解决。后面我看下把您的和我的合并一下一起处理。- @echo off & setlocal EnableDelayedExpansion
- @cd /d "%~dp0"
- if exist gpuz.xml (del gpuz.xml)
- if exist ")" (del ")")
- call GPU-Z.exe -dump GPUZ.xml
- for /f %%a in ('type "GPUZ.xml" ^|find /c /i "<cardname>Microsoft </cardname>"') do set "nums=%%a"
- if %nums% EQU 1 (call :Cari)
- for /f "skip=1 tokens=1 delims=:" %%a in ('type "GPUZ.xml" ^|findstr /n "<cardname>Microsoft </cardname>"') do set "kas=%%a" & set /a ka2=!kas!-3
- echo %ka2%
-
- :Cari
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<gpuname>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set gpuname=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<vendorid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set vendorid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<deviceid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set deviceid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<subvendorid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subvendorid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subsysid=%%c)
-
- echo %vendorid% %deviceid%-%subvendorid% %subsysid%
- echo %gpuname%
-
- set Cars=1
- :installDrive
-
- ::10400 Comet Lake GT2
- if "%gpuname%"=="Intel Xe" (start /min "" ".\DG1\DVrun.bat" & Goto End)
- if "%gpuname%"=="Arc Alchemist" (start /min "" ".\A380\DVrun.bat" & Goto End)
- if "%gpuname%"=="Alder Lake" (start /min "" ".\Intel_Video\DvRun.bat" & Goto End)
- if "%vendorid%"=="8086" (start /min "" ".\Intel_Video\DvRun.bat" & Goto End)
-
- if "%vendorid%"=="1002" (echo 我是AMD显卡 & start /min "" ".\AMD580\DvRun.bat" & Goto End)
-
- if "%gpuname%"=="GK208" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GK208B" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GF119" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GF108" (echo 我是NVIDIAGT730显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GK208B" (echo 我是NVIDIAGT730显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
-
- ::T600 T400 T1000
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB1-10DE 1488" (echo 我是NVIDIAT600显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB2-10DE 1489" (echo 我是NVIDIAT400显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB0-103C 12DB" (echo 我是NVIDIAT1000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%gpuname%"=="GA106" (echo 我是NVIDIAA2000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%gpuname%"=="GP106" (echo 我是NVIDIAP2000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- ::P1000 P620 P400
- if "%gpuname%"=="GP107" (echo 我是NVIDIAP620显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
-
- if "%vendorid%"=="10DE" (echo 我是NVIDIA游戏显卡 & start /min "" ".\NV3050\DvRun.bat" & Goto End)
- :End
- if !Cars! EQU 2 (call :Qlzc)
- if !nums! EQU 2 (call :Carii)
- :Qlzc
- if exist gpuz.xml (del gpuz.xml)
- if exist GPUZ2.xml (del GPUZ2.xml)
- if exist ")" (del ")")
- exit
-
- :Carii
- (for /f "tokens=*" %%n in (GPUZ.xml) do (
- set /a m+=1
- if !m! LEQ !ka2! (echo %%n)
- )) >GPUZ2.xml
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ2.xml" ^|find "<gpuname>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set gpuname=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ2.xml" ^|find "<vendorid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set vendorid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ2.xml" ^|find "<deviceid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set deviceid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ2.xml" ^|find "<subvendorid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subvendorid=%%c)
- for /f "delims=^> tokens=1,*" %%a in ('type "GPUZ2.xml" ^|find "<subsysid>"') do (for /f "delims=^< tokens=1,*" %%c in ("%%b") do set subsysid=%%c)
- echo %vendorid% %deviceid%-%subvendorid% %subsysid%
- echo %gpuname%
- set /a Cars=!Cars!+1
- call :installDrive
复制代码
作者: yakeyun 时间: 2022-7-18 10:54
整合后的版本:- @echo off & setlocal EnableDelayedExpansion
- @cd /d "%~dp0"
- if exist gpuz.xml (del gpuz.xml)
- if exist ")" (del ")")
- call GPU-Z.exe -dump GPUZ.xml
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<gpuname>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set gpuname!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<vendorid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set vendorid!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<deviceid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set deviceid!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<subvendorid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set subvendorid!n!=%%c
- set /a n+=1
- )
- set n=1
- for /f "tokens=1,* delims=>" %%a in ('type "GPUZ.xml" ^|find "<subsysid>"') do (
- for /f "tokens=1,* delims=<" %%c in ("%%b") do set subsysid!n!=%%c
- set /a n+=1
- )
-
- echo 显卡一:%gpuname1% %vendorid1% %deviceid1%-%subvendorid1% %subsysid1%
- echo 显卡二:%gpuname2% %vendorid2% %deviceid2%-%subvendorid2% %subsysid2%
-
- set gpuname=%gpuname1%
- set vendorid=%vendorid1%
- set deviceid=%deviceid1%
- set subvendorid=%subvendorid1%
- set subsysid=%subsysid1%
-
- set installs=1
-
- :installDrive
- ::10400 Comet Lake GT2
- if "%gpuname%"=="Intel Xe" (start /min "" ".\DG1\DVrun.bat" & Goto End)
- if "%gpuname%"=="Arc Alchemist" (start /min "" ".\A380\DVrun.bat" & Goto End)
- if "%gpuname%"=="Alder Lake" (start /min "" ".\Intel_Video\DvRun.bat" & Goto End)
- if "%vendorid%"=="8086" (start /min "" ".\Intel_Video\DvRun.bat" & Goto End)
-
- if "%vendorid%"=="1002" (echo 我是AMD显卡 & start /min "" ".\AMD580\DvRun.bat" & Goto End)
-
- if "%gpuname%"=="GK208" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GK208B" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GF119" (echo 我是NVIDIAGT710显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GF108" (echo 我是NVIDIAGT730显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
- if "%gpuname%"=="GK208B" (echo 我是NVIDIAGT730显卡 & start /min "" ".\NV710\DvRun.bat" & Goto End)
-
- ::T600 T400 T1000
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB1-10DE 1488" (echo 我是NVIDIAT600显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB2-10DE 1489" (echo 我是NVIDIAT400显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%vendorid% %deviceid%-%subvendorid% %subsysid%"=="10DE 1FB0-103C 12DB" (echo 我是NVIDIAT1000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%gpuname%"=="GA106" (echo 我是NVIDIAA2000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- if "%gpuname%"=="GP106" (echo 我是NVIDIAP2000显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
- ::P1000 P620 P400
- if "%gpuname%"=="GP107" (echo 我是NVIDIAP620显卡 & start /min "" ".\NVT400\DvRun.bat" & Goto End)
-
- if "%vendorid%"=="10DE" (echo 我是NVIDIA游戏显卡 & start /min "" ".\NV3050\DvRun.bat" & Goto End)
- :End
-
- if !installs! EQU 2 (call :Qlzc)
- if not !gpuname2! EQU "" (
- set gpuname=%gpuname2%
- set vendorid=%vendorid2%
- set deviceid=%deviceid2%
- set subvendorid=%subvendorid2%
- set subsysid=%subsysid2%
- set /a installs=!installs!+1
- call :installDrive
- )
- :Qlzc
- if exist gpuz.xml (del gpuz.xml)
- if exist GPUZ2.xml (del GPUZ2.xml)
- if exist ")" (del ")")
- exit
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |