Saved Bookmarks
| 1. |
Solve : GTR and LSS seem to fail for large sizes? |
|
Answer» 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 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.Correct. Because batch files can only handle 32bit Integers.Change your IF comparison to use quotes. Code: [Select]IF "%FILESIZE%" GTR "%SIZELIMIT%" Goto No 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 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.Well I tested it a few times with quotes and it worked. No it does not just compare the first character.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? You know you can copy and paste text from the cmd window. Wouldn't that be a lot EASIER then posting a SCREEN shot? Quote from: BeemerBiker on February 14, 2017, 07:12:39 AM Strange - I tested it on both the Win10 command prompt and the Micro$oft VS 14You realize there is no difference between the two? You are just in a different directory.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. Quote from: BeemerBiker on February 13, 2017, 04:30:14 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 |
|