Batch File Selection Statement- If

This is a discussion on Batch File Selection Statement- If within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I am attempting to use an if statement so that if a user enters a 1 it opens a file ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21