In tip 1071, we used CHKDSK in a batch script, to determine the free space on a disk drive.

Thanks to Chris Dickerson, we can use DF.

Typing DF /? at a command prompt, displays:

<b>
Chris Dickerson (R) DiskFree Version 1.00.080
Copyright (c) Chris Dickerson 1999. All rights reserved.
Free for use by anyone

DF                 Display space info on all fixed system drives
DF /?              Help
DF \[path\]          UNC or regular path, displays freespace available to you
DF \[path\] \[bytes\]  In a batch file, returns a "1" if there is enough space for
                   \[bytes\]</b>
Typing DF, displays information similar to:
<b>
Chris Dickerson (R) DiskFree Version 1.00.080
Copyright (c) Chris Dickerson 1999. All rights reserved.
Free for use by anyone

Drive  free             total            capacity
-----  ---------------- ---------------- --------
C:\    817,383,424      2,138,540,032    38.22 %
D:\    1,228,214,272    2,146,764,800    57.21 %</b>
Typing DF <Path> (c:\ or \\Server\C$) displays:
<b>
Chris Dickerson (R) DiskFree Version 1.00.080
Copyright (c) Chris Dickerson 1999. All rights reserved.
Free for use by anyone

Total free bytes available to you: 816,039,936
Total bytes available to you     : 2,138,540,032</b>
Typing DF <Path> BytesRequired sets the ERRRORLEVEL to 1 if there is enough room for BytesRequired, or 0 if there is not. Using the above display:

DF C:\ 500000 sets ERRORLEVEL to 1.
DF C:\ 900000 sets ERRORLEVEL to 0

I have scripted DFree.bat to return the following environment variables:

 Name   Type   D e s c r i p t i o n 
 DRV_TOT   numeric   The total drive size, in bytes. 
 DRV_FREE   numeric   The free space available, in bytes 

The syntax is:

DFree <Path>

Using the above C:\ display, DRV_FREE is set to 817383424 and DRV_TOT is set to 2138540032.

DFree.bat contains:

<b>
@echo off
if not "%1"<h1><a name="_goto_begin_echo_Syntax_DF_DriveLetter_goto_end_begin_for_f_Skip_4_Tokens_1_2_Delims_i_in_df_exe_1_do_call_parse_i_j_goto_end_parse_if_i_1">"" goto begin
@echo Syntax: DF DriveLetter
goto end
:begin
for /f "Skip=4 Tokens=1,2 Delims=:" %%i in ('df.exe %1') do call :parse "%%i" "%%j"
goto end
:parse
if /i %1</a></h1>"Total free bytes available to you" goto free
set DRV_TOT=%2
set DRV_TOT=%DRV_TOT: =%
set DRV_TOT=%DRV_TOT:"=%
set DRV_TOT=%DRV_TOT:,=%
set /a DRV_TOT=%DRV_TOT%
goto end
:free
set DRV_FREE=%2
set DRV_FREE=%DRV_FREE: =%
set DRV_FREE=%DRV_FREE:"=%
set DRV_FREE=%DRV_FREE:,=%
set /a DRV_FREE=%DRV_FREE%
:end</b>