Setbatchfiles

Home > Articles > Home & Office Computing > Microsoft Windows Desktop

Since a batch file is fundamentally just a text file, one can be created in any sort of simple text editor, and the suffix can later be changed to.bat or.cmd.Most people find it easiest to simply edit one from the command line, either straight in DOS or in a shell window launched from within Windows®. Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session. Syntax SET variable SET variable=string SET 'variable=string' SET 'variable=' SET /A 'variable=expression' SET /P variable=promptString SET ' Key variable: A new or existing environment variable name e.g. num string: A text string to assign to the variable.

Setbatchfiles
  1. Prompting for Input
< BackPage 12 of 13Next >
This chapter is from the book

Batch File Set Current Directory

Setbatchfiles
Windows XP Under the Hood: Hardcore Windows Scripting and Command Line Power

This chapter is from the book

This chapter is from the book

Windows XP Under the Hood: Hardcore Windows Scripting and Command Line Power

Prompting for Input

If your batch file has to print a message you definitely don't want the users to miss, use the pause statement to make the batch file sit and wait until they've read the message and acknowledged it. Here's an example:

If you want to ask a user whether to proceed after a mishap, or if you want the batch file to prompt for input filenames or other data, you can use the new extended set /p command. Set /p reads a user's response into an environment variable, where it can be tested or used as a command argument. Here's an example:

These commands ask the user to type a response, examine the leftmost letter with %answer:,1%, and take the appropriate action only if the user types a valid response. In fact, this is a good pattern to remember. Not quite narwhal pdf free download.

Related Resources

  • Book $47.99
  • eBook (Watermarked) $38.39

Set Batch File To Run As Administrator

  • Book $23.99