Skip navigation

JSI Tip 7891. How do I rapidly retrieve a volume's size, free space, and allocation unit, in a batch, using freeware?


Using NTFSInfo.exe, I have scripted DrvInfo.bat to return a volume's size, free space, and allocation unit.

The syntax for using DrvInfo.bat is:

DrvInfo DriveLetter DSize FSpace Alloc

Where:

DriveLetter is the volume's drive letter, with or without the colon (:).

DSize is a call directed numeric environment variable that will contain the volume's size, in megabytes (MB).

FSpace is a call directed numeric environment variable that will contain the volume's free space, in megabytes (MB).

Alloc is a call directed numeric environment variable that will contain the volume's Allocation Unit size, in bytes.

NOTE: See How do I retrieve a volume's size, free space, and allocation unit, in a batch, using standard commands?

DrvInfo.bat contains:

@echo off
if \{%4\}==\{\} @echo Syntax: DrvInfo DriveLetter DSize FSpace Alloc&exit /b 1
setlocal ENABLEDELAYEDEXPANSION
set work=%1
set drive=%work:~0,1%
if not exist %drive%: @echo DrvInfo: %1 does NOT exist&endlocal&exit /b 2
@echo Volume size            :>%TEMP%\DrvInfo.tmp
@echo Free space             :>>%TEMP%\DrvInfo.tmp
@echo Bytes per cluster      :>>%TEMP%\DrvInfo.tmp
set /a cnt=0
for /f "Tokens=2 Delims=:" %%a in ('ntfsinfo %drive%^|Findstr /B /G:%TEMP%\DrvInfo.tmp') do (
 set /a cnt=!cnt! + 1
 call :setit!cnt! %%a
)
del /q %TEMP%\DrvInfo.tmp
endlocal&set /a %2=%DSize%&set /a %3=%FSpace%&set /a %4=%Alloc%
exit /b 0
:setit1
set DSize=%1
goto :EOF
:setit2
set FSpace=%1
goto :EOF
:setit3
set Alloc=%1



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish