0

I use batch files a lot to make my computer do things for me. But mostly i make it do things that I've already decided. Like opening my hidden file if I'm alone, or start playing a specific playlist. These things are simple enough for a beginner like me.

But now I want to try to make it define by itself if it should open this file or the other. For instance, I write the command line(see below) to ask me a question to which I have to answer:

set /p input==how much on 10?

As you can see, I may answer with any number from 0 to ten. And I can write a command line to tell it what to do for each value, like:

if %input%==10 then ten

and so on...

but what if I didn't want to write all these command lines one by one if two or three values have the same input? For instance, what if at and below 4 I wanted it to open my timetable, and at and below 8 my playlist, and over 8 I wanted it to open another playlist?

Maybe using the 'greater than' or 'less than' signs?

I tried doing that and it doesn't work. But maybe i'm doing it wrong?

1

2 Answers 2

1

Try the below code

@echo off
set /p input=how much on 10?
if %input% LSS 4 (
msg * Less Than 4
) else (
 if %input% LSS 8 msg * Less Than 8 )

Here msg is command that is executed when the condition is met. You can use it to run your program by modifying it as below

@echo off
set /p input=how much on 10?
if %input% LSS 4 (
YourProgram1
) else (
 if %input% LSS 8 YourProgram2 )

Other options you can use instead of LSS are

EQU Equal to

NEQ Not equal to

LSS Less than

LEQ Less than or equal to

GTR Greater than

GEQ Greater than or equal to

2
  • YES! That was exactly what I was looking for.
    – Ashfaaq
    Apr 3, 2015 at 14:52
  • +1 because it's weird that you're at 1 rep for 56 days and posting code. Normally, that would be very suspicious. Apr 3, 2015 at 17:28
0

Have a look at the choice command to create menus in batch files. See http://www.robvanderwoude.com/choice.php and http://www.wikihow.com/Create-Options-or-Choices-in-a-Batch-File for details

If you still prefer set /p then have a look at http://www.sevenforums.com/tutorials/78083-batch-files-create-menu-execute-commands.html

1
  • Thank you. Even though this did not really answer my question, i got to learn something.
    – Ashfaaq
    Apr 3, 2015 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .