Skip navigation

JSI Tip 5350. How can I determine a drive size and free space in a Windows XP batch?

Windows XP includes the Fsutil utility which can be used to query the size of a volume and the number of available free space bytes.

I have scripted DriveSF.bat to return the drivesize and drivefree environment variables. The syntax for using DriveSF.bat is:

call drivesf <Drive_Letter:>


call drivesf C:

DriveSF.bat contains:

@echo off
if \{%1\}==\{\} goto syntax
set drive=%1
if not "%drive:~1,1%" EQU ":" goto syntax
for /f "Skip=1 Tokens=*" %%i in ('fsutil volume diskfree %drive%') do set line=%%i&call :parse
set line=
set drive=
goto :EOF
@echo Syntax DriveSF Drive_Letter:
set drive=
set drivesize=
set drivefree=
goto :EOF
if defined drivesize set drivefree=%line:~30,99%&goto :EOF
set drivesize=%line:~30,99%

NOTE: See tip 5351 ยป How can display drive information from the Windows XP command-line?

Hide 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.