VOGONS


errorlevels

Topic actions

First post, by pandarsson

User metadata
Rank Newbie
Rank
Newbie

Is choice the only dosbox command that returns an errorlevel? I was trying to make a move.bat, but in order to safely delete the old file, I need copy to give me an errorlevel. If the copy is successful, I need a 0, while if it's not, I need a 1. Here is the contents of the batch file:

@echo off
if ()==(%1) goto ERRORA
if exist %1 goto MOVE
echo The file "%1" does not exist.
goto END

:MOVE
if ()==(%2) goto ERRORB
copy %1 %2
if errorlevel 0 goto DEL
goto ERRORC

:DEL
del %1
goto END

:ERRORA
echo You must specify which file to move.
goto END

:ERRORB
echo You must specify a location.
goto END

:ERRORC
echo Unable to complete command.

:END

The offending if statement is under :MOVE. Am I doing something wrong? Am I expecting too much? Is there another way of which I haven't thought?

Yes, I know I could do other things for a move command, but I like figuring out batch files. Sue me. I suppose if nothing else, I can use the bat2com utility posted somewhere on the net and convert it in dosemu, but I wanted to check here first.

Reply 1 of 7, by MiniMax

User metadata
Rank Moderator
Rank
Moderator

I guess you are expecting too much. Not much, but too much. Maybe Qbix will be inspired to set errorlevel after the move.

Until then, you could do something like this:

del %2
copy %1 %2
if exist %2 goto DEL

DOSBox 60 seconds guide | How to ask questions
_________________
Lenovo M58p | Core 2 Quad Q8400 @ 2.66 GHz | Radeon R7 240 | LG HL-DT-ST DVDRAM GH40N | Fedora 32

Reply 2 of 7, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

copy doesn't set an errorlevel, because we never thought of adding it. (no game that we own uses it)

Water flows down the stream
How to ask questions the smart way!

Reply 3 of 7, by pandarsson

User metadata
Rank Newbie
Rank
Newbie

MiniMax:

Until then, you could do something like this: del %2 copy %1 %2 if exist %2 goto DEL […]
Show full quote

Until then, you could do something like this:

del %2
copy %1 %2
if exist %2 goto DEL

That's pretty clever. It'd work even if %2 was a directory, wouldn't it?

Qbix:

copy doesn't set an errorlevel, because we never thought of adding it. (no game that we own uses it)

Would it be a pain to add? I can't think of one that uses it, either, but I know that, for instance, say, Sierra used some complicated batch files in their installed games. Again, I don't know of any that would use that, but I have to wonder if one might.

Reply 5 of 7, by MiniMax

User metadata
Rank Moderator
Rank
Moderator
pandarsson wrote:

That's pretty clever. It'd work even if %2 was a directory, wouldn't it?

EXIST works for directories, yes.

DOSBox 60 seconds guide | How to ask questions
_________________
Lenovo M58p | Core 2 Quad Q8400 @ 2.66 GHz | Radeon R7 240 | LG HL-DT-ST DVDRAM GH40N | Fedora 32

Reply 6 of 7, by ADDiCT

User metadata
Rank Oldbie
Rank
Oldbie

The easiest solution would probably be to use 4DOS, which has a "move" command, and returns errorlevels for internal commands (such as copy, delete, etc.). I've created quite a few complex batches that work very well in DOSBox.

Reply 7 of 7, by gidierre

User metadata
Rank Member
Rank
Member
pandarsson wrote:

I was trying to make a move.bat

at any rate I'd change its name to something other than move.bat
or else
at the prompt you'll probably need to always type the extension for it to work the way you expect