Script .. what the problem..

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Script .. what the problem..

#1 Post by mor.bas » 03 Feb 2013 07:09

Whats get wrong in this script?

The script need to check for 20 GB on c and if there is continue with it's process..

please advice...

SETLOCAL ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "C""') DO SET FreeBytes=%%n
SET /A FreeSpace=!FreeBytes:~0,-10!
ECHO %FreeSpace%
IF %FreeSpace% LSS 20 (
"%~d0\MessageBox.vbs" "You need at least 20 Gb on c to preform the installation."
EXIT 1
) ELSE (
call "%~d0\Commands.bat"
call "%~dp0\setup.exe"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script .. what the problem..

#2 Post by foxidrive » 03 Feb 2013 07:28

Remove the /A as it is not a mathematical command.

SET /A FreeSpace=!FreeBytes:~0,-10!

and the trailing ) is missing.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script .. what the problem..

#3 Post by foxidrive » 03 Feb 2013 07:35

I would also check for megabytes in the case that a drive is very full


Code: Select all

@echo off
SETLOCAL ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
FOR /F %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "C:""') DO SET FreeBytes=%%n
SET FreeSpace=!FreeBytes:~0,-6!
if not defined freespace set freespace=0
ECHO %FreeSpace%
IF %FreeSpace% LSS 20000 (
"%~d0\MessageBox.vbs" "You need at least 20 Gb on c to perform the installation."
EXIT /b 1
) ELSE (
call "%~d0\Commands.bat"
call "%~dp0\setup.exe"
)
pause

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Script .. what the problem..

#4 Post by mor.bas » 03 Feb 2013 07:54

Thanks
If you check that is lss then 20 gb it's not including there is no space at all?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script .. what the problem..

#5 Post by foxidrive » 03 Feb 2013 09:01

The line that checks if the freespace variable is defined will handle situations when the drive is completely full.

I changed the way that works in the code I posted in the previous message. See above.

Post Reply