Get user input Batch files

Discussion in 'Programmer's Corner' started by Anthony Quah, Mar 24, 2009.

  1. Anthony Quah

    Thread Starter Active Member

    Dec 1, 2007
    80
    0
    hi guy,

    I am doing some batch files...can I know what is the format to get input from user ...example the user enter 1 will direct to folder A or user enter 2 will direct to folder B..I am have problem to define the variable and string...this is just my hobby to learn a batch files...any suggestion or format i can refer? thanks
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    There IS no apparatus provided for input of parameters.

    However, you can retrieve parameters that were passed on the command line.
    %0 - returns how the batch file was invoked
    %1 thru %9 - returns the individual parameters
    SHIFT - causes %0 thru %9 to shift down 1.

    Example:

    C:\>type t.bat
    echo %0
    echo %0 %1 %2 %3 %4 %5
    SHIFT
    echo %0 %1 %2 %3 %4 %5

    C:\>T a b c d e f g

    C:\>echo T
    T

    C:\>echo T a b c d e
    T a b c d e

    C:\>SHIFT

    C:\>echo a b c d e f
    a b c d e f
    C:\>
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
  4. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    THere were a number of user-input commands written when DOS was The System. I do not remember the names, however. :(

    THe OP may wish to look into alternate shells, such as NDOS, 4DOS, etc.

    --Rich
     
Loading...