A Batch File query

T

Trevor L.

I set up this batch file

STEP1:
dir C:\Windows\Temp\*.*
@ECHO Do you want to delete these files or quit?
@ECHO Y. Delete files
@ECHO N. Go to next step
@ECHO Q. Quit
@CHOICE /C:YNQ
IF ERRORLEVEL == 3 GOTO QUIT
IF ERRORLEVEL == 2 GOTO STEP2
del C:\Windows\Temp\*.*

:STEP2
(similar to STEP1 with a different directory)
etc.

The last few lines are
:QUIT
@echo this is the QUIT step
pause

The CHOICE command returned the message
'CHOICE' is not recognised as an internal or external command,
operable program or batch file.

These lines were then printed
C:\Batch Files>IF ERRORLEVEL == 3 GOTO QUIT
this is the QUIT step

C:\Batch Files>pause
Press any key to continue . . .

So ERROLEVEL must have been equal to 3 !!

Is there an alternative to CHOICE under Windows XP ?
 
P

PopS

The bad news is, Choice isn't included in the XP commands. The
good news is, however, you can lift it from most any DOS and from
all over the web. And, it's legal to download it from the web.
If you don't have a win95 or 98 laying around you can get it
from, and searching doesn't do it, let me know and I'll send you
a copy of choice.exe. My machine's clean, but you should virus
check it anyway when it arrives if you want me to send it.

There's an excellent DOS group at microsoft.public.msdos-batch,
or something like that.

HTH,
Pop
 
T

Trevor L.

Klaus said:
Trevor L. wrote :

Use the SET /P command.

E.g.

SET /P inp=Delete files (Y/N/Q)?

Thank you both

I'll try SET. If it works OK, I'll use it.

But I might google for choice.exe anyway.
Where do I install it (or copy it to, to be more precise) ?
C:\Windows\system32 ?
 
K

Klaus Jorgensen

Trevor L. wrote :
Thank you both

I'll try SET. If it works OK, I'll use it.

But I might google for choice.exe anyway.
Where do I install it (or copy it to, to be more precise) ?
C:\Windows\system32 ?

Yes - the system32 folder is ok.
The CHOICE and SET commands differs in the way they handles user input.
The CHOICE command accepts a one character input that returns an error
code. The CHOICE program is standard in Windows Server 2003.
The SET command returns a character string in an environment variable.
To check for values, use the IF command.


/klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top