-1

I am trying to write a small batch script which will get the free space and then write to a report (.txt) whether or not that disk needs to be cleaned down if it is over 80% full. I have never used batch for scripting so i'm using this as a little project.

The issue i am having is, i get the message to clean down the disk no matter what the argument is. Here's my code:

wmic /node:"%COMPUTERNAME%" LogicalDisk Where DriveType="3" Get DeviceID,FreeSpace|find /I "c:" > test.txt

FOR /F "eol=; tokens=2,3* delims=, " %%i in (test.txt) do @echo %%i

if [%%i] GEQ [10] (echo "Clean up is needed" > cleanupneeded.txt)

if someone could let me know if this is even possible i'd greatly appreciate it.

Thanks

user2099445
  • 103
  • 7

2 Answers2

1

Try this. I didn't test your code - just that the syntax was not quite right.

FOR /F "eol=; tokens=2,3* delims=, " %%i in (test.txt) do if %%i GEQ 10 echo "Clean up is needed" > cleanupneeded.txt
foxidrive
  • 40,353
  • 10
  • 53
  • 68
1

GEQ means "greater or equal. what you are looking for is LEQ - "less or equal". (or possibly LSS - "less")

and, of course, the if needs to be on the same line as the for, or enclosed in parentheses, i assume you just replaced it with the echo for testing.

ths
  • 2,858
  • 1
  • 16
  • 21