Receiving "Missing Operand" error when launching the following script?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
eax22
Posts: 13
Joined: 15 Apr 2017 15:02

Receiving "Missing Operand" error when launching the following script?

#1 Post by eax22 » 15 Apr 2017 15:05

Yeah can someone tell me why? This file is supposed to measure the size of the folder it resides in, and echo the size.

Code: Select all

setlocal enableelayedexpansion
set /a value=0
set /a sum=0
for /r %1 %%i in (*) do (
set /a value=%%~zI/1024
set /a sum=!sum!+!value!
)
echo %sum% k
pause >nul

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Receiving "Missing Operand" error when launching the following script?

#2 Post by Squashman » 15 Apr 2017 21:54

For variables are case sensitive. Says so right in the help file.
Variable names are case sensitive, so %i is different
from %I.


You are also missing a "d" in enabledelayedexpansion

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Receiving "Missing Operand" error when launching the following script?

#3 Post by aGerman » 16 Apr 2017 05:21

Furthermore...
  • ! is the logical NOT operator and may cause side effects. Apart from FOR variables and dynamic variables (such as %random%) the variable name is sufficient in a SET /A statement.
  • If you want to add a value to an existing variable you may rather use the += operator.

Code: Select all

set /a "sum+=value"

... where even variable value coul be replaced with %%~zI/1024.

Also note that numeric values in batch are limited to the size of a 32bit signed integer. Thus, the greatest numeric value is 2147483647.

Steffen

eax22
Posts: 13
Joined: 15 Apr 2017 15:02

Re: Receiving "Missing Operand" error when launching the following script?

#4 Post by eax22 » 16 Apr 2017 06:53

Wow I didn't know that variables were case sensitive... thanks for that. It fixed my problem.

eax22
Posts: 13
Joined: 15 Apr 2017 15:02

Re: Receiving "Missing Operand" error when launching the following script?

#5 Post by eax22 » 16 Apr 2017 07:12

Also thanks for the advice, I'll make sure to edit the way I add up to a value.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Receiving "Missing Operand" error when launching the following script?

#6 Post by Squashman » 16 Apr 2017 19:44

eax22 wrote:Wow I didn't know that variables were case sensitive... thanks for that. It fixed my problem.

Always a good idea to read the help file for the command you are using. Will save you time in the long run.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Receiving "Missing Operand" error when launching the following script?

#7 Post by ShadowThief » 16 Apr 2017 22:28

eax22 wrote:Wow I didn't know that variables were case sensitive... thanks for that. It fixed my problem.

Only variables used by for loops are case sensitive. (Most likely because they're limited to a single character.)

Post Reply