1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Resolved Win XP batch files

Discussion in 'Windows XP' started by Tony King, 2013/01/02.

  1. 2013/01/02
    Tony King

    Tony King Well-Known Member Thread Starter

    Joined:
    2002/05/12
    Messages:
    140
    Likes Received:
    1
    I have been trying find a way to set up a choice in a batch file - i.e., display a message "Do you want to XXX? (Y/N)?" but I can't see any way to implement a user input and perform the relevant action.
    Is this possible or am I wasting my time?
     
  2. 2013/01/03
    SpywareDr

    SpywareDr SuperGeek WindowsBBS Team Member

    Joined:
    2005/12/31
    Messages:
    3,752
    Likes Received:
    338
    Code:
    
    @echo off
    :Loop
    cls
    set Answer=
    set /p Answer=  "Do you want to xxx? (Y/N):  "
    for %%x in (y Y) do if  "%Answer% "== "%%x" goto Yes
    for %%x in (n N) do if  "%Answer% "== "%%x" goto No
    goto Loop
    :Yes
    echo You answered Yes
    goto Cleanup
    :No 
    echo You answered No
    :Cleanup
    set Answer=
    :EOF
     
    Tony King likes this.

  3. to hide this advert.

  4. 2013/01/04
    Tony King

    Tony King Well-Known Member Thread Starter

    Joined:
    2002/05/12
    Messages:
    140
    Likes Received:
    1
    :) Many thanks SpywareDr for your reply. It looks highly promising and I shall try it immediately.
    I spent some time poring over 'Batch Files' in O'Reilly's 'XP in a Nutshell' but it was somewhat unclear as to accepting an input and taking action.
    I will reply again when I've set up the file.
     
  5. 2013/01/04
    Tony King

    Tony King Well-Known Member Thread Starter

    Joined:
    2002/05/12
    Messages:
    140
    Likes Received:
    1
    Latest update :
    Thank you SpywareDr for a very helpful response. The only drawback was that I am using the basic DOS commands whereas you suggested 'for', which only applies to script files.
    However, there was sufficient information for me to be able to use the DOS 'if' statement
    (i.e., if "%Answer% "== "N" goto end etc. etc) and it all works like a charm.
    Thanks again.
     
    Last edited: 2013/01/04
  6. 2013/01/04
    PeteC

    PeteC SuperGeek Staff

    Joined:
    2002/05/10
    Messages:
    28,896
    Likes Received:
    389
    Please mark your thread as 'Resolved'.

     
  7. 2013/01/04
    SpywareDr

    SpywareDr SuperGeek WindowsBBS Team Member

    Joined:
    2005/12/31
    Messages:
    3,752
    Likes Received:
    338
  8. 2013/01/05
    Tony King

    Tony King Well-Known Member Thread Starter

    Joined:
    2002/05/12
    Messages:
    140
    Likes Received:
    1
    Thank you PeteC, but I don't need reminding about resolution. In fact I have already clicked on 'Mark as solved' twice but WindowsBBS is not actioning this.
     
  9. 2013/01/05
    PeteC

    PeteC SuperGeek Staff

    Joined:
    2002/05/10
    Messages:
    28,896
    Likes Received:
    389
    Strange - it works for me - marked as Resolved.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.