JSI Tip 3687. Batch script returns drive size and freespace.

Jerold Schulman

May 13, 2001

1 Min Read
ITPro Today logo in a gray background | ITPro Today


Using GetSysInfo.exe, I have scripted GetDriveInfo.BAT, which returns the following environment variables:

Environment    Variable

D e s c r i p t i o n

jsidrive

 The drive letter that you queried. 

jsisize

 A character-based variable containing the drive size in bytes. 

jsisizemb

 An arithmetic variable containing the drive size in megabytes. 

jsifree

 A character-based variable containing the drive freespace in bytes. 

jsifreemb

 An arithmetic variable containing the drive freespace in megabytes. 

GetDriveInfo.bat has one parameter, the drive letter you are querying. If you ommit the parameter, drive C is queried. If you query an invalid drive letter, jsisize will be 0.

GetDriveInfo.BAT contains:

@echo offif {%1}=={} set jsidrive=C&goto getdriveset jsidrive=%1set jsidrive=%jsidrive:"=%set jsidrive=%jsidrive::=%set jsidrive=%jsidrive:=%:getdriveset jsisize=0set jsifree=0set /a jsisizemb=0set /a jsifreemb=0for /f "Skip=8 Tokens=1-3 Delims=:" %%i in ('getsysinfo.exe') do call :parse %%i %%j %%k set len=set char=goto :EOF:parseif /i "%jsidrive%" NEQ "%1" GOTO :EOFset jsisize=%2#set jsifree=%3#set /a len=0:parse1set /a len=%len% + 1for /f %%n in ('@echo %%jsisize:~%len%^,1%%') do set char=%%nIf "%char%" NEQ "#" goto parse1set jsisize=%jsisize:#=%set /a len=%len% - 6for /f %%n in ('@echo %%jsisize:~0^,%len%%%') do set jsisizemb=%%nset /a jsisizemb=%jsisizemb%set /a len=0:parse2set /a len=%len% + 1for /f %%n in ('@echo %%jsifree:~%len%^,1%%') do set char=%%nIf "%char%" NEQ "#" goto parse2set jsifree=%jsifree:#=%set /a len=%len% - 6for /f %%n in ('@echo %%jsifree:~0^,%len%%%') do set jsifreemb=%%nset /a jsifreemb=%jsifreemb%



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like