Subscribe to Windows IT Pro
May 24, 2002 12:00 AM

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

Windows IT Pro
InstantDoc ID #76654
Rating: (0)

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:>

Example:

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
:syntax
@echo Syntax DriveSF Drive_Letter:
set drive=
set drivesize=
set drivefree=
goto :EOF
:parse
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?



Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.