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:

                               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\]
Typing DF, displays information similar to:
                              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 %
Typing DF <Path> (c:\ or \\Server\C$) displays:
                              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
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:

                              @echo off                              if not "%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

"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