- echo off
-
- echo list disk > diskpart.txt
-
- diskpart /s diskpart.txt
-
- echo sel disk 0 > diskpart.txt
-
- echo detail disk >> diskpart.txt
-
- diskpart /s diskpart.txt>DiskInfo.txt
-
- for /f "tokens=3" %%a in ('type DiskInfo.txt ^| find "类型 :"') do (
- set "str=%%a"
- )
- if /i "%str%" equ "NVMe" (
- set str=Disk0 Type : SSD
- )
- if /i "%str%" equ "USB" (
- set str=Disk0 Type : USB
- )
- if /i "%str%" equ "SATA" (
- set str=Disk0 Type : HDD
- )
- echo %str%
-
-
- echo sel disk 1 > diskpart.txt
-
- echo detail disk >> diskpart.txt
-
- echo diskpart /s diskpart.txt>DiskInfo.txt
-
- diskpart /s diskpart.txt>DiskInfo.txt
-
- for /f "tokens=3" %%a in ('type DiskInfo.txt ^| find "类型 :"') do (
- set "str=%%a"
- )
- if /i "%str%" equ "NVMe" (
- set str=Disk1 Type : SSD
- )
- if /i "%str%" equ "USB" (
- set str=Disk1 Type : USB
- )
- if /i "%str%" equ "SATA" (
- set str=Disk1 Type : HDD
- )
- echo %str%
-
-
- echo sel disk 2 > diskpart.txt
-
- echo detail disk >> diskpart.txt
-
- echo diskpart /s diskpart.txt>DiskInfo.txt
-
- diskpart /s diskpart.txt>DiskInfo.txt
-
- for /f "tokens=3" %%a in ('type DiskInfo.txt ^| find "类型 :"') do (
- set "str=%%a"
- )
- if /i "%str%" equ "NVMe" (
- set str=Disk2 Type : SSD
- )
- if /i "%str%" equ "USB" (
- set str=Disk2 Type : USB
- )
- if /i "%str%" equ "SATA" (
- set str=Disk2 Type : HDD
- )
- echo %str%
- if exist diskpart.txt del /f /q diskpart.txt
- if exist DiskInfo.txt del /f /q DiskInfo.txt
- pause
复制代码
为什么我这个代码DISK 2不存在时还是显示上一步的结果?我需要当DISK 2或 DISK 1不存在时,不显示任何结果。 |