JSI Tip 1071. How can I determine the freespace on a disk drive?

contains Freedisk:

This program checks for free disk space and returns a 0 if there is enough space and a 1 if there isn't.
Usage freedisk drive (minimum bytes)

DiskSpace.bat uses CHKDSK to return the following environment variables:

 Name   Type   D e s c r i p t i o n 
 DRV   string   The drive letter 
 DRV_TYP   string   The type of file system (NTFS / FAT). 
 DRV_TOT   numeric   The total drive size, in kilobytes. 
 DRV_FREE   numeric   The free space available, in kilobytes 
 DRV_ALLOC   numeric   The allocation unit size, in bytes. 

To use DiskSpace.bat:

DiskSpace DriveLetter

DiskSpace.bat contains:

@echo off
if "%1"

"" goto syntax set DRV=%1 set DRV=%DRV::=% if "%DRV%"

"" goto syntax goto begin :syntax @echo Syntax: DiskSpace DriveLetter goto end :begin if exist %TEMP%\Diskspace.%DRV%.%computername% del /f /q %TEMP%\Diskspace.%DRV%.%computername% REM If you have SP4, you could improve performance by using chkdsk %DRV%: /c /i > "%TEMP%\Diskspace.%DRV%.%computername%" chkdsk %DRV%: > "%TEMP%\Diskspace.%DRV%.%computername%" for /f "Tokens=1-9 Delims= " %%i in (%TEMP%\Diskspace.%DRV%.%computername%) do call :parse "%%i" "%%k" "%%p" goto end :parse if %2

"of" goto type if %2

"total" goto tot if %2

"available" goto avail if %2

"in" goto units goto end :type set DRV_TYP=%3 set DRV_TYP=%DRV_TYP:"=% set DRV_TYP=%DRV_TYP:.=% goto end :tot set DRV_TOT=%1 set DRV_TOT=%DRV_TOT:"=% set /a DRV_TOT=%DRV_TOT% goto end :avail set DRV_FREE=%1 set DRV_FREE=%DRV_FREE:"=% set /a DRV_FREE=%DRV_FREE% goto end :units set DRV_ALLOC=%1 set DRV_ALLOC=%DRV_ALLOC:"=% set /a DRV_ALLOC=%DRV_ALLOC% goto end :end

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.