Reputation: 341
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?
Upvotes: 2
Views: 774
Reputation: 2112
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
)
Upvotes: 1
Reputation: 59305
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%
Upvotes: 1