2

Say I have a file name that is really long, like: asdfiiemqpovnweujweurvqvqv.txt

and I want sdfiiem, which is the second character to the eighth character. How would I check if my file name has that string of characters in that specific location?

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
Seanzies93
  • 321
  • 1
  • 6
  • 12

2 Answers2

1

It is possible to get a substring from an environment variable, so the following will work:

@echo off
set filename=%1
echo %filename:~1,7%
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
1

Check a string for a substring in a batch file (Windows)?

Here is what I could find that has already been posted.

set YourString=asdfiiemqpovnweujweurvqvqv.txt

If NOT "%YourString%"=="%YourString:sdfiiem=%" (
    echo Yes
) else (
    echo No
)
Community
  • 1
  • 1
Hayden
  • 2,082
  • 1
  • 14
  • 18