标题: [数值计算] 批处理代码,硬盘容量计算,如何实现常规数字显示? [打印本页]
作者: ygqiang 时间: 2024-10-24 15:54 标题: 批处理代码,硬盘容量计算,如何实现常规数字显示?
本帖最后由 ygqiang 于 2024-11-2 15:59 编辑
批处理代码,硬盘容量计算,如何实现常规数字显示?
比如32G\128G\256G\500G\1T- @echo off & setlocal enabledelayedexpansion
- echo 代码开始
- cls
-
- @echo off&setlocal enabledelayedexpansion
- set "_NVMe=SSD-NVMe"
- set "_USB=USB"
- set "_SATA=HDD/SSD-SATA"
- for /f "tokens=2,4,5" %%a in ('"echo list disk|diskpart|findstr /irc:"磁盘 *[0-9]""') do (
- for /f "tokens=3" %%i in ('"(echo sel disk %%a & echo detail disk & echo list part)|diskpart|findstr /irc:"类型 *:""') do (
- if defined _%%i echo.&echo.&echo Disk%%a Type: !_%%i! %%b %%c
- )
- )
-
- pause >nul
- exit
复制代码
运行后显示如下:
Disk0 Type: HDD/SSD-SATA 465 GB
Disk1 Type: SSD-NVMe 238 GB
Disk2 Type: USB 117 GB
Disk3 Type: USB 931 GB
Disk4 Type: USB 28 GB
作者: ygqiang 时间: 2024-10-24 15:56
本帖最后由 ygqiang 于 2024-10-29 15:51 编辑
参考下面的代码,可以显示常规容量,256G\500G- @echo off
- setlocal enabledelayedexpansion
-
- COLOR 04
- COLOR 84
-
- COLOR f4
- COLOR fc
- COLOR 7c
- COLOR 74
- echo.
- echo.
- echo --------------硬盘信息如下:
- echo.
- set "StrDrive="
- for /f "tokens=1* delims==" %%a in ('"wmic DiskDrive where MediaType='Fixed hard disk media' get Model,Size /value | findstr ="') do (
- if "%%a" == "Model" (
- for /f %%i in ("%%b") do (
- set StrDrive=!StrDrive!,品牌:%%i
- )
- ) else if "%%a" == "Size" (
- for /f "delims=" %%i in ("%%b") do (
- set SizeGB=%%i
- set /a SizeGB=!SizeGB:~, -6!/1000
- set StrDrive=!StrDrive!,容量:!SizeGB!GB
- set "StrDrive=!StrDrive:~1!"
- echo,!StrDrive!
- set "StrDrive="
-
- )
- )
- )
-
-
- pause
复制代码
最新版本的Windows 11 专业版24h2,不内置wmic命令了?
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |