Thread: Batch File Selection Statement- If

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    5

    Batch File Selection Statement- If

    I am attempting to use an if statement so that if a user enters a 1 it opens a file but if they enter a 2 or a 3 it opens another file. Is this possible to do? I would have thought it so.

    Does anyone has any idea or links that might help me find the answer?

    Thanks in advance,


    Peter

  2. #2
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    There's the CHOICE command , but its only suppported in Win95/98. If you're using 2000/XP then you might be able to download it and use it in your machine.

    more info about CHOICE

    for opening files you can use the START command (in case you were asking about that , too)

    hope this is what you're looking for
    Last edited by Brain Cell; 05-05-2005 at 09:41 AM.
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Cheat and use the for command
    for %answer in (1) do echo "option 1"
    for %answer in (2) do echo "option 2"

    A cool article on the For command:
    http://weblogs.sqlteam.com/robv/articles/4099.aspx

  4. #4
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    or you can make a C\C++ program that with a switch statement then use system() to open files (i.e : system("start filename.extention");)
    Last edited by Brain Cell; 05-05-2005 at 10:35 PM. Reason: disabled smilies
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    5
    Code:
    for %answer in (1) do "Car safe crossing script.swf"
    for %answer in (2) do "Cars Crashing on Bridge.swf"
    This is what I tried for the for statement. It didn't work. Can anyone see where I may have gone wrong?

    Thanks,

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Quote Originally Posted by heylin
    Code:
    for %answer in (1) do "Car safe crossing script.swf"
    for %answer in (2) do "Cars Crashing on Bridge.swf"
    This is what I tried for the for statement. It didn't work. Can anyone see where I may have gone wrong?

    Thanks,
    You need to use the Start command like Brain Cell said.

    for %answer in (1) do start "Car safe crossing script.swf"
    for %answer in (2) do start "Cars Crashing on Bridge.swf"

    Also I'm not 100% on the syntax - look it up.
    Last edited by nickname_changed; 05-05-2005 at 09:41 PM.

  7. #7
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    On further inspecion I don't think it is possible with For. Do what Brain Cell said and write something in C/C++ (or if you want to finish it this year, maybe C#)

  8. #8
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Hold on. Did you even try typing "If" into the console?

    if %a == 1 (start someThing.swf) else (start anotherThing.swf)

    Works on XPSP2 at least.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Or just realise that cmd.exe, whilst a big improvement on command.com, is still fundamentally a broken shell incapable of anything but the most basic of tasks.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. batch file introduction in multiprocesses program
    By c_geek in forum C Programming
    Replies: 0
    Last Post: 03-27-2008, 01:52 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. check my code ( if statement, file existance )
    By Shadow in forum C Programming
    Replies: 1
    Last Post: 10-04-2001, 11:13 AM