Page 1 of 1

what am i doing wrong (if, errorlevel, ren)

Posted: 13 Jul 2020 04:29
by linzzer
this should be so easy, yet I'm super lost. What am i doing wrong? :S
why is the errorlevel code being 50% ignored?

https://i.postimg.cc/SsCfTgmB/zinger.png
https://i.postimg.cc/5ymq1jYp/Clipboard02f.png

Code: Select all

if exist zzzplaces.sqlite ren places.sqlite zpirplaces.sqlite
echo %errorlevel%
::pause
SAME RESULT if not errorlevel 0 goto :ren1 // if errorlevel 0 goto :ren1
if errorlevel 1 goto :ren2

:ren1
ren zzzplaces.sqlite places.sqlite
goto end

::if exist zpirplaces.sqlite ren places.sqlite zzzplaces.sqlite
::if errorlevel 0 goto :ren2

:ren2
ren places.sqlite zzzplaces.sqlite
ren zpirplaces.sqlite places.sqlite

:end

pause

Re: what am i doing wrong (if, errorlevel, ren)

Posted: 13 Jul 2020 05:04
by penpen
linzzer wrote:
13 Jul 2020 04:29
this should be so easy, yet I'm super lost. What am i doing wrong? :S
why is the errorlevel code being 50% ignored?
All is working as intended (by Microsoft).
The command "if errorlevel <number>" specifies a true condition only if the previous program run by Cmd.exe returned an exit code equal to or greater than number.
Here you seeem to have changed your code:

Code: Select all

:: from
if errorlevel  0 goto :ren1
if errorlevel  1 goto :ren2

:: to
if errorlevel  1 goto :ren1
if errorlevel  0 goto :ren2
Herre the errorlevel changed from '1' to '0'.


penpen

Re: what am i doing wrong (if, errorlevel, ren)

Posted: 13 Jul 2020 07:15
by linzzer
>Here you seeem to have changed your code:

yea i know because I was changing things around. so how do I jump to :ren2 ? if one file exists?

Re: what am i doing wrong (if, errorlevel, ren)

Posted: 14 Jul 2020 02:10
by penpen
You could do the following:

Code: Select all

if exist "filename" goto :ren2

penpen

Re: what am i doing wrong (if, errorlevel, ren)

Posted: 14 Jul 2020 15:35
by linzzer
yea, that's what I ended up doing.

thanks :)