Seanzies93
Seanzies93

Reputation: 341

How do I extract only part of a file name in a batch script

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

Answers (2)

Hayden
Hayden

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

Thomas Weller
Thomas Weller

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

Related Questions