Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Making [Y/N] questions in batch files  (Read 218710 times)

0 Members and 1 Guest are viewing this topic.

macdad-



    Expert

    Thanked: 40
    Re: Making [Y/N] questions in batch files
    « Reply #15 on: January 25, 2009, 06:22:57 PM »
    the NT version is the one that you would want.
    If you dont know DOS, you dont know Windows...

    Thats why Bill Gates created the Windows NT Family.

    PirateSamir

      Topic Starter


      Rookie

      Re: Making [Y/N] questions in batch files
      « Reply #16 on: January 26, 2009, 10:57:24 AM »
      3.1 or 3.5?
      Quantum bonus pro quantum numerus.

      Dias de verano

      • Guest
      Re: Making [Y/N] questions in batch files
      « Reply #17 on: January 26, 2009, 11:23:47 AM »
      3.1 or 3.5?

      Either, or NT4, or Win2K resource kit

      PirateSamir

        Topic Starter


        Rookie

        Re: Making [Y/N] questions in batch files
        « Reply #18 on: January 26, 2009, 11:38:43 AM »
        k thnx, i got 3.5
        gonna learn to use it now :D
        Quantum bonus pro quantum numerus.

        Dias de verano

        • Guest
        Re: Making [Y/N] questions in batch files
        « Reply #19 on: January 26, 2009, 11:43:35 AM »
        k thnx, i got 3.5
        gonna learn to use it now :D
        Code: [Select]
        Microsoft Windows XP [Version 5.1.2600]
        (C) Copyright 1985-2001 Microsoft Corp.

        C:\>choice /?
        CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

        /C[:]choices Specifies allowable keys. Default is YN
        /N           Do not display choices and ? at end of prompt string.
        /S           Treat choice keys as case sensitive.
        /T[:]c,nn    Default choice to c after nn seconds
        text         Prompt string to display

        ERRORLEVEL is set to offset of key user presses in choices.

        PirateSamir

          Topic Starter


          Rookie

          Re: Making [Y/N] questions in batch files
          « Reply #20 on: January 26, 2009, 11:55:00 AM »
          ok, 2 questions
          how would define your default choice?
          and
          what is errorlevel? (i've seen it quite oftenly in batch files)  ???
          Quantum bonus pro quantum numerus.

          Dias de verano

          • Guest
          Re: Making [Y/N] questions in batch files
          « Reply #21 on: January 26, 2009, 12:44:09 PM »
          ok, 2 questions
          how would define your default choice?
          and
          what is errorlevel? (i've seen it quite oftenly in batch files)  ???


          Example

          Default choice is Y, timeout is 10 seconds

          Code: [Select]
          choice /C:YN /T:Y,10 Press Y or N
          echo errorlevel is: %errorlevel%

          If Y was pressed (or timeout occurred) the %errorlevel%  will be 1 (because Y is choice 1) and if N was pressed %errorlevel% will be 2 (because N is the second choice)

          errorlevel is a system variable which is set by a program. Often 0=no error, 1 or more means an error. Choice uses it to pass the key pressed.

          Code: [Select]
          S:\>chtest1.bat
          Press Y or N [Y,N]?Y
          errorlevel is: 1

          S:\>chtest1.bat
          Press Y or N [Y,N]?N
          errorlevel is: 2

          PirateSamir

            Topic Starter


            Rookie

            Re: Making [Y/N] questions in batch files
            « Reply #22 on: January 26, 2009, 12:49:58 PM »
            so can errorlevel be used for anything else?
            Quantum bonus pro quantum numerus.

            Dias de verano

            • Guest
            Re: Making [Y/N] questions in batch files
            « Reply #23 on: January 26, 2009, 12:59:32 PM »
            so can errorlevel be used for anything else?

            Yes.

            Code: [Select]
            dir *.txt
            if %errorlevel% GTR 0 echo "No text files"

            Plenty of information if you use Google.


            PirateSamir

              Topic Starter


              Rookie

              Re: Making [Y/N] questions in batch files
              « Reply #24 on: January 26, 2009, 01:03:35 PM »
              ok thnx :)
              Quantum bonus pro quantum numerus.

              ht

              • Guest
              Re: Making [Y/N] questions in batch files
              « Reply #25 on: January 08, 2011, 03:20:54 PM »
              Code: [Select]
              @ECHO OFF

              :choice
              set /P c=Are you sure you want to continue[Y/N]?
              if /I "%c%" EQU "Y" goto :somewhere
              if /I "%c%" EQU "N" goto :somewhere_else
              goto :choice


              :somewhere

              echo "I am here because you typed Y"
              pause
              exit

              :somewhere_else

              echo "I am here because you typed N"
              pause
              exit


              Thanks hiteshsavla - Exactly what I required, saved me a lot of time.  (I write batch files so infrequently these days that it takes time to get back into it)