user2570202
user2570202

Reputation: 77

Batch Script to test free space of drive

I would like help making a batch script to test if there is a certain amount of storage available in a drive in Winodws 7, thanks in advance.

Upvotes: 0

Views: 2253

Answers (2)

Endoro
Endoro

Reputation: 37569

fsutil volume diskfree C: | find /i "avail free"

Upvotes: 1

foxidrive
foxidrive

Reputation: 41234

I had this squirreled away from a previous request.

@echo off
set "low="
for /f "tokens=3" %%a in ('dir c:\ /-p 2^>nul') do set "size=%%a"
for /f "tokens=1-4 delims=," %%a in ("%size%") do (
if "%%d"=="" set low=1
set gb=%%a
set mb=%%b
)

if %gb%%mb% LEQ 2000 set low=1

If defined low (
echo email here with %size%
echo WARNING: Drive C: has %size% free 
) else (
echo Drive C: has %gb%.%mb% free GB
)
pause

Upvotes: 0

Related Questions