Discussion on:

26
Comments

Join the conversation!

Follow via:
RSS
Email Alert
0 Votes
+ -
Editor
Do you create and use batch files on a regular basis? Are you using the Choice command?
4 Votes
+ -
Moderator
Echo off
:Comment
Choice /M "Do you want to make a comment?"
If Errorlevel 2 Goto No
If Errorlevel 1 Goto Yes

:No
Echo You selected No, you have nothing to add
Goto End

:Yes
Echo You selected Yes, Are you sure?
Goto Comment

:End

Hehe! {;-)
although we shouldn't be encouraging you. grin
1 Vote
+ -
Used regularly
benb@... 20th Oct 2011
I use batch files for various uses regularly - such as copying data from one drive to another with various options set, disabling software, displaying IP information, etc.

They are quite powerful and fairly simple to use.
0 Votes
+ -
I attempted to download this from the "downloads" page and got only the URL for the topic.
0 Votes
+ -
Editor
Working now
Mark W. Kaelin 21st Oct 2011
I just clicked the link and it downloaded okay. Please try again and I apologize for the trouble.
0 Votes
+ -
I was unaware of 'CHOICE', but I can see myself using it in the future.
1 Vote
+ -
Moderator
Prior to that I used a small BATCH file helper called "ASK.COM", it even
had color prompts!
I made an entire menu for my old DOS 6.22 IBM PS2 Model 5500SX using
CHOICE, along with a couple of other tools. So simple that even my kids,
who were like 10yrs, 5 yrs, and 3 yrs old at the time, could start the games
they wanted to play.

ps---thanks for the +1! {;-)
0 Votes
+ -
Mark, thanks
Plant Doctor 24th Oct 2011
I agree. As often as I use bat files I had not known about this command. I, too, can see myself using it in the future. Great tip.
You'd be amazed what you can do in PowerShell... time to let go of batch files!
0 Votes
+ -
Batch Files
Craig_B 24th Oct 2011
Yes, PowerShell is a great tool however there are times when Batch files do the trick. It's about picking the right tool for the job, which could be Batch files, PowerShell, VB Script, GUI application, etc.
- add a "Pause" after :End. Otherwise Windows will close the command window after you press a key.
0 Votes
+ -
thanks. just run it several times and was trying to figure out how to stop it from closing.
thanks again.
0 Votes
+ -
nice trick
gmaran23@... 2nd Nov 2011
C:\Users\maran>pause /?
Suspends processing of a batch program and displays the message
Press any key to continue . . .

Handy trick.
0 Votes
+ -
I tried a few searches on microsoft.com to "... download the Choice command and add it to ... XP", but no luck for me. Could you point to where I might be able to download it? Thanks in advance, and have a great day.
0 Votes
+ -
batcom
DoubleBarrel 24th Oct 2011
Used a program called batcom for years, it would compile a batch file into an executable and allow you to put it on a customers computer without fear of someone modifying it without permission. It also had additional commands that you could add. Oh for the "Good old days"???
But your test runs just fine and choice /? works also
2 Votes
+ -
Batch Files
sparker@... 24th Oct 2011
I started on PCs when DOS 1.0 came out, so I have used batch files for years to do almost everything. I have to laugh now, when I pull up a command box to type in a command-line or create a quick bat file. Most of the techs I work with have never seen a bat file, much less make one. I usually hear an incredulous "You know how to do that???"
I still remember one of my students telling me "DOS is Boss" after he finally got some real world experience.

I haven't used CHOICE in a while but I do have my USB master Ghost boot key and it's got a pretty extensive MENUITEM boot menu to automate loading nic drivers for all of our different PCs. Other than that, I've migrated most everything to WSH and Powershell.
Yeah I still use them, got a couple of old ones used for generating default company configurations for Cisco devices which where originally created about 8 years ago and I have been maintaining ever since, it gets used on average about 3 times a week (and not just by me) I keep updating it every so often.

I have noticed that at the same time as introducing things like PowerShell, MS have been making significant improvements to Batch, If you are familiar with Batch you should check out the improvements.
As an example Batch now supports code blocks using parenthesis, so wizard57's code can be improved thusly... (Sorry for the plagiarism, I'm being lazy)

Echo off
:Comment
Choice /M "Do you want to make a comment?"

If Errorlevel 2 Goto (
Echo You selected No, you have nothing to add
Goto End
)
If Errorlevel 1 (
Echo You selected Yes, Are you sure?
Goto Comment
)
:end

Other new features present in windows 7 that you should check out before abandoning Batch are
For command can split an input for processing, as well as reading through a file line by line processing each line.
Set command now has the ability to do basic calculations
Timeout is the windows equivalent of sleep.
Actually Windows 7 SP1 does not have any BATCH language enhancements compared to Windows XP SP3.
All the features you mentioned exist in XP.
I compared via Windiff the documentation for XP and WIN7.

These are the only BATCH related changes from XP to Win7...

New dynamic environment variable %HIGHESTNUMANODENUMBER%

The following commands have new switches

COPY switch for symbolic links

XCOPY switches for symbolic links
and unbuffered I/O. Recommended for very large files

DIR switches for alternate data streams of files
and Not content indexed Files
and Reparse Points

DEL switches for Not content indexed Files
and Reparse Points

START switches for AFFINITY
and NODE ( aka NUMA )

What documentation did I compare? If any interest I can post the details.
-1 Votes
+ -
In batch files the symbol = is never taken into account; furthermore the line:
if errorlevel X
is not interpreted as
if errorlevel=X
but instead:
if errorlevel>=X
This motivates the need to list the numbers in decreasing order.
Since at least XP you can do this in batch...

if %Errorlevel% EQU 1 goto 1

the full list of compare ops...
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal
0 Votes
+ -
SET /P
Zenith545 29th Oct 2011
Since Microsoft decided NOT to include CHOICE in XP, I have become familiar with the SET /P command:
SET /P variable=[promptString]

Great for creating mini-menus.
0 Votes
+ -
Good article, and I liked the way the options are displyed with the charactor map. I see it for the first time.
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.