0

So basicly, is there any way to make it so a Batch file doesnt need an exact answer to do an action. For example:

if %c%=images goto :images

The above means that I must type in the exact word, images, and if I add any more words it wont go to the :images label. How would I make it to go to a label using just a word from a sentence that you input.
For example if it asks me:

Where would you like to go?

And I say:

The image section please.

Then it takes me to the image section without the need for just saying image.

Is this possible?

BDM
  • 3,760
  • 3
  • 19
  • 27

2 Answers2

2

You could use find.

echo %c% | find /i "image" >NUL && goto images

That'll also provide case-insensitive matching. Furthermore, you can similarly use findstr to match based on a regular expression if you need finer tuning of your match.

If you're curious about how the | and && above do their magic, see command redirection for more info.

rojo
  • 24,000
  • 5
  • 55
  • 101
2

There's a similar question here: Batch file: Find if substring is in string (not in a file)

The accepted answer could work in your case:

if /i "%c:image=%" neq "%c%" goto images

This technique uses string substitution to replace the word image with nothing (strip the word from the string you're searching), then compare it to the original string. If they're different, then the substring was found.

Community
  • 1
  • 1
Nate Hekman
  • 6,507
  • 27
  • 30