- @echo off & setlocal enabledelayedexpansion
- for /f "delims=g" %%a in ('cmd /u /cEcho,有') do set "Tab=%%a"
- set w=wmic diskdrive where "MediaType like 'fixed%%'"
- (for /f "delims=" %%a in ('%w% get model^,size/value^|find "="') do (
- for /f "tokens=1,2delims==" %%b in ("%%a") do (
- if /i "%%b" == "model" (
- set "model=%%~nxc" & set /a i+=1
- set /p=硬盘!i!:%Tab%<nul
- ) else (
- call :GetSize %%~nxc000 size
- if !size! gtr 102400 (
- set /a size/=1024 & set "G=GB"
- ) else set "G=MB"
- set /p=大小: !size:~,-2!.!size:~-2!!G!%Tab%<nul
- set /p=型号: !model!<nul
- echo,
- )
- )
- ))>DiskInfo.txt
-
- set w=wmic logicaldisk where "DriveType='3'"
- for /f "tokens=1-3" %%a in ('%w% get freespace^,name^,size^|find ":"')do (
- set /p=分区%%b%Tab%<nul
- call :GetSize %%a000 free
- call :GetSize %%c000 size
- set /a used=size-free
- if !size! gtr 102400 (
- set "G=GB" & set /a size/=1024,used/=1024
- ) else set "G=MB"
- set /a used=1000*used/size
- if "!used:~,-1!" == "" set "used=0!used!"
- set /p=大小: !size:~,-2!.!size:~-2!!G!%Tab%<nul
- if !free! gtr 102400 (set /a free/=1024 & set "G=GB") else set "G=MB"
- set /p=剩余: !free:~,-2!.!free:~-2!!G!%Tab%<nul
- set /p=使用率: !used:~,-1!.!used:~-1!%%<nul
- echo,
- )>>DiskInfo.txt
- start "" NotePad DiskInfo.txt
- exit/b
-
- :GetSize
- set "num=%1" & set "n=" & set "%2="
- for %%a in (16 8 4 2 1) do (
- if not "!num:~%%a!"=="" set /a n+=%%a & set "num=!num:~%%a!"
- )
- set "num=%1" & set /a n-=6
- for /l %%a in (!n! -1 1) do (
- set "s=!num:~,-%%a!"
- if "!s:~,1!" == "0" set "s=!s:~1!"
- set /a m=s%%1048576,s/=1048576
- set "%2=!%2!!s!"
- set "num=!m!!num:~-%%a!"
- )
- if not defined %2 (
- set "%2=!num:~,-1!"
- ) else if "!%2:~,1!" == "0" set "%2=!%2:~1!"
复制代码
|