help fix my code

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
xhai
Posts: 39
Joined: 13 Jun 2013 09:33

help fix my code

#1 Post by xhai » 06 Mar 2014 08:01

Hi guys i have a code but i don't know how to fix it.. the problem is it doesn't display "Filesize is Mismatched!" when the bytesize is not equal..

The problem occur when the set file have <space> "DVD<space>2.iso".. it doesn't detect the space so it will work it the set file is "DVD.iso"

will this require extra codes?...

thank you i hope you fix my problem..


Code: Select all

:vSize
set file=DVD 2.iso
set bytesize=1673494528
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA
if %size% NEQ %bytesize% (set ERROR=1)
if defined ERROR (
echo.
echo                      Filesize is Mismatched!
echo.
TIMEOUT /t 2 >nul
pause
goto start
) ELSE (
echo.
echo                      Filesize is Matched.
echo.
TIMEOUT /t 2 >nul
)
goto vSize

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

Re: help fix my code

#2 Post by ShadowThief » 06 Mar 2014 14:46

Code: Select all

set "file=DVD 2.iso"

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

Re: help fix my code

#3 Post by Squashman » 06 Mar 2014 14:50

Why are you setting the error variable with an IF and then using an IF to check that variable. Why not just do all your logic in one if? If you are going to use the ERROR variable then you should clear it out before the IF statement that checks the sizes.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: help fix my code

#4 Post by penpen » 06 Mar 2014 18:23

You should use a default for loop instead of the for/F loop and use double quotes:

Code: Select all

FOR %%A IN ("%file%") DO set size=%%~zA

penpen

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: help fix my code

#5 Post by xhai » 07 Mar 2014 04:59

penpen wrote:You should use a default for loop instead of the for/F loop and use double quotes:

Code: Select all

FOR %%A IN ("%file%") DO set size=%%~zA

penpen


Thank you all and Mr.penpen the code works now..

can you explain me what is the difference between those codes..

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

Re: help fix my code

#6 Post by foxidrive » 07 Mar 2014 08:07

xhai wrote:can you explain me what is the difference between those codes..


Read the help from here and then ask any further questions you have: type this at the cmd prompt

FOR /?

Post Reply