Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7735657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:33:21+00:00 2026-06-01T07:33:21+00:00

I’d like to have a notification that informs me when my hard disk space

  • 0

I’d like to have a notification that informs me when my hard disk space is getting low. I’m running Windows 7 Professional and I think a quick batch file could handle this. I’ll schedule it to run once a day. This is what I have so far:

This finds the remaining disk space using the “dir” command and the “find” command. It stores the value in Var1. (This works for me)

@echo off
FOR /F "tokens=*" %%i in ('dir ^| find "free"') do SET WinVer=%%i 
FOR /F "tokens=1-3 delims=]-" %%A IN ("%WinVer%" ) DO ( 
SET Var1=%%A 
)

This pulls the number from the the result and removes the commas. The result will look like “111222333444” without the quotes: (This works for me)

set Var1=%Var1:~10,15%
set Var1=%Var1:,=%

This checks if the value in Var1 is less than 100 GB (my hypothetical disk space floor). If so, it creates a file called “lowSpace.txt” that I’ll see at some point. (This doesn’t work for me)

if %Var1% leq 100000000000 dir > lowSpace.txt

This “if” statement is causing me problems. My free disk space is about 150 GB (or 150000000000), so the if condition should fail and the “dir > lowSpace.txt” should not be running, but it does anyway.

  • If I increase the constant in the “if” statement from 100000000000 to 500000000000, the file “lowSpace.txt” is created as I expect.

  • Or, if I increase the constant again from 100000000000 to 500000000000 and change the condition from “leq” to “geq”, the file “lowSpace.txt” is created when I would expect it to not be created.

Am I comparing my numbers wrong? Or is something wrong with my “if” statement? The code seems to consider 150 GB to be both greater than and less than 100 GB.


Here is my full script:

@echo off
FOR /F "tokens=*" %%i in ('dir ^| find "free"') do SET WinVer=%%i 
FOR /F "tokens=1-3 delims=]-" %%A IN ("%WinVer%" ) DO ( 
SET Var1=%%A 
) 
set Var1=%Var1:~10,15%
set Var1=%Var1:,=%

if %Var1% leq 100000000000 dir > lowSpace.txt
@echo on
@echo %Var1%

Note that 100 GB isn’t my real hard disk space floor. I’m just using that number to test my code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:33:22+00:00Added an answer on June 1, 2026 at 7:33 am

    I asked and answered this very question at Windows batch file IF failure – How can 30000000000000 equal 40000000000?. Your problem is Windows batch cannot handle numbers greater than ~2 GB. If treats any number greater than 2 GB as equal to 2 GB.
    I posted a simple work around that prefixes the numbers with zeros and forces a string comparison instead of a numeric comparison.

    Note, you can also use WMIC to get the free space of any given drive:

    for /f "tokens=2" %%S in ('wmic volume get DriveLetter^, FreeSpace ^| findstr "^C:"') do set freeSpace=%%S
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.