Question:

Writing a batch file... Need a variable.?

by  |  earlier

0 LIKES UnLike

For a batch file, how do you get it to prompt you for a drive letter?

And within the batch file, what variable string do I use to propogate the supplied drive letter?

 Tags:

   Report

3 ANSWERS


  1. There is no pre-defined variable string for the drive letter.  You use whatever string you've read the drive letter into.

    SET /P driveletter="Enter a drive letter.  "

    REM do something with that drive:

    dir %driveletter%:\

    Hope that helps.


  2. You don't specify the OS, which would help.

    If you are using XP, try

    Windows 2000/XP

    In Windows 2000, user input can be obtained quite easily by using SET /P

    SET /P variable=[promptString]

    This command will display an optional promptString where the user can type in a string and press Enter. The typed string will then be stored in the specified environment variable variable.

  3. set /P variable=promptstring

    Example: set /P drv="Please enter a drive letter: "

    To see the results, simply: echo %drv%

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.