Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: GTR and LSS seem to fail for large sizes  (Read 3450 times)

0 Members and 1 Guest are viewing this topic.

BeemerBiker

    Topic Starter


    Starter

    • Yes
    • Riders Club Page
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
GTR and LSS seem to fail for large sizes
« on: February 13, 2017, 08:43:32 AM »
Was trying to determine which ISOs are BluRay and which are DVD and I picked 9gb as the size cutoff.  %~z1 gave the correct size but GTR failed to calculate properly.  Maybe I did something wrong or perhaps there is another way to differentiate the two types.

echo %1 %~z1
@ECHO OFF
SET SIZELIMIT=9000000000
SET FILESIZE=%~z1

IF %FILESIZE% GTR %SIZELIMIT% Goto No

ECHO DVD
PAUSE
GOTO :EOF

:No
ECHO BluRay
PAUSE
GOTO :EOF

Thanks for looking.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: GTR and LSS seem to fail for large sizes
« Reply #1 on: February 13, 2017, 09:26:44 AM »
Correct.  Because batch files can only handle 32bit Integers.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: GTR and LSS seem to fail for large sizes
« Reply #2 on: February 13, 2017, 09:36:02 AM »
Change your IF comparison to use quotes.

Code: [Select]
IF "%FILESIZE%" GTR "%SIZELIMIT%" Goto No

Salmon Trout

  • Guest
Re: GTR and LSS seem to fail for large sizes
« Reply #3 on: February 13, 2017, 01:06:24 PM »
@ECHO OFF
echo Wscript.echo eval(WScript.Arguments(0)) > evaluate.vbs
echo %1 %~z1
SET SIZELIMIT=9000000000
SET FILESIZE=%~z1
for /f "delims=" %%A in ('cscript evaluate.vbs "%filesize% > %sizelimit%"') do set result=%%A
If %result% equ -1 goto no
ECHO DVD
PAUSE
GOTO :EOF
:No
ECHO BluRay
PAUSE
GOTO :EOF

BeemerBiker

    Topic Starter


    Starter

    • Yes
    • Riders Club Page
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: GTR and LSS seem to fail for large sizes
« Reply #4 on: February 13, 2017, 04:30:14 PM »
The suggestion to use quotes did not work.  Possibly only the first letter is checked.  However, Salmon's evaluate.vbs worked fine.  Sizeof or strlen would have worked OK if they existed.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: GTR and LSS seem to fail for large sizes
« Reply #5 on: February 13, 2017, 06:29:03 PM »
Well I tested it a few times with quotes and it worked. No it does not just compare the first character.

BeemerBiker

    Topic Starter


    Starter

    • Yes
    • Riders Club Page
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: GTR and LSS seem to fail for large sizes
« Reply #6 on: February 14, 2017, 07:12:39 AM »
Strange - I tested it on both the Win10 command prompt and the Micro$oft VS 14 one and it appears only to check the first character.   Are you using the power shell or some other extension?


Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: GTR and LSS seem to fail for large sizes
« Reply #7 on: February 14, 2017, 09:57:01 AM »
You know you can copy and paste text from the cmd window.  Wouldn't that be a lot easier then posting a screen shot?

Strange - I tested it on both the Win10 command prompt and the Micro$oft VS 14
You realize there is no difference between the two?  You are just in a different directory.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: GTR and LSS seem to fail for large sizes
« Reply #8 on: February 14, 2017, 10:25:17 AM »
As Squashman stated, it doesn't only compare the first character.

The confusion is in expecting a numeric comparison. The use of quotation marks makes it no longer a numeric comparison, instead, it is comparing the two values as strings.

Code: [Select]
if "2" lss "10" (echo lower) else (echo higher)
outputs "higher", becasue it is comparing the string "2" to the string "10" alphanumerically.

The "solution" is to have it use leading zeroes:

Code: [Select]
if "02" lss "10" (echo lower) else (echo higher)

outputs "lower".

using VBScript via evaluate.vbs tends to be the better alternative if you want to exceed the rather basic math capabilities of batch.
I was trying to dereference Null Pointers before it was cool.

Salmon Trout

  • Guest
Re: GTR and LSS seem to fail for large sizes
« Reply #9 on: February 14, 2017, 01:21:07 PM »
Sizeof or strlen would have worked OK if they existed.
@echo off
set mystring=9000000000
call :strlen %mystring%
echo string length %slen%
goto end

:strlen
set slen=0
set tempstring=%1
:loop
set tempstring=%tempstring:~0,-1%
set /a slen+=1
if "%tempstring%"=="" goto :eof
goto loop

:end
echo done

pause