[Resolved] Alternative xcopy function to Choice - Carriage return as accepted character possible?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
koko
Posts: 38
Joined: 13 Oct 2016 00:40

[Resolved] Alternative xcopy function to Choice - Carriage return as accepted character possible?

#1 Post by koko » 18 Sep 2019 00:44

I came across this superb script by by aGerman which is a functional replacement to the choice command using xcopy behind the scenes, executing the conditional errorlevel commands only if the character input matches a predefined list (like choice /n). Was ideal as I was looking for something that didn't beep on invalid inputs as choice does.
aGerman wrote:
02 Nov 2015 13:36
That function may help...
What I was wondering is whether the Enter key/carriage return could be defined as a valid input character along with the other valid 'choices' characters, as I was hoping for a way to define a default command to execute if the prompt is 'skipped' by pressing Enter. The other non-choice-like set /p prompts in my script I made to behave in this manner to quickly apply defaults (in those prompts I have it conditionally apply commands if nothing was entered).

Wasn't sure of forum etiquette of necro'ing topics so decided to make a new topic, hope no one minds.
Last edited by koko on 18 Sep 2019 17:30, edited 1 time in total.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Alternative xcopy function to Choice - Carriage return as accepted character possible?

#2 Post by aGerman » 18 Sep 2019 10:02

What I was wondering is whether the Enter key/carriage return could be defined as a valid input
Basically you can. The subroutine contains the line

Code: Select all

if defined c (
which checks if you pressed Enter without any other input before (which is the case if c is not defined at this position). You can't define it in the map variable though. And of course it needs a separate handling.

Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Alternative xcopy function to Choice - Carriage return as accepted character possible?

#3 Post by dbenham » 18 Sep 2019 10:59

You might also want to look at :getKey and :getAnyKey that use REPLACE instead of XCOPY.

Both forms can return a value representing a carriage return, and have an option to specify valid characters, including Carriage Return.


Dave Benham

koko
Posts: 38
Joined: 13 Oct 2016 00:40

Re: Alternative xcopy function to Choice - Carriage return as accepted character possible?

#4 Post by koko » 18 Sep 2019 17:27

aGerman wrote:
18 Sep 2019 10:02
Basically you can. The subroutine contains the line

Code: Select all

if defined c (
which checks if you pressed Enter without any other input before (which is the case if c is not defined at this position). You can't define it in the map variable though. And of course it needs a separate handling.
dbenham wrote:
18 Sep 2019 10:59
You might also want to look at :getKey and :getAnyKey that use REPLACE instead of XCOPY.

Both forms can return a value representing a carriage return, and have an option to specify valid characters, including Carriage Return.
Thank you both. Will look into it.

Post Reply