1.

Solve : How do I get free disk space using a batch file??

Answer»

I need to install a program and to do this I need to USE an unattended batch file to see if there is enough available disk space and then allow the batch processing to continue if there is enough.

How do I get the free space on a disk and how do I compare it to what is needed?

Thanks
In the ressourcekit is a command called diruse.
This can show you the diskspace in kb or mb...

You can compare this with the needed space with an if ... equ ... statement.

Using the native dir command you have to extract the last line an bring it in a variable with a for statement.

for /f ... ('dir | find "Bytes frei') do ...

Depends how the output looks like.

On my machine it is 1.886.625.280 Bytes frei

So you have to compare it in bytes. I never tried it. So I don't know if there are restricitions how "big" the numbers can be.

hope this helps
uliThe NUMERIC limit for XP seems to be 2147483647. If you add 1 you will get -2147483648.

If you don't care about single bytes for your calculation then cut off the last 3 DIGITS and calculate in KB (where 1kb = 1000 bytes) like this:

Code: [Select]SET drive=C:
FOR /f "tokens=3 delims= " %%a in ('"dir %drive%\|find "bytes free""') do set free=%%a
SET free=%free:,=%& rem eliminate commas in number
SET free=%free:.=%& rem eliminate dots in number
SET free=%free:~0,-3%& rem divide by 1000 by cutting off the last 3 digits
SET MIN=4000& rem minimum 40000000 bytes
IF %free% LSS %min% ECHO.NOT ENOUGH SPACE&GOTO:EOF
ECHO.INSTALL ...
DOS IT HELP ?



Discussion

No Comment Found