Substring in file name in a directory.

November 23, 2009 at 07:23:35
Specs: Windows XP
I've a set of jar files in a directory in the format "abc-<version>-def.jar". I want to extract version of a jar file which contains a particular substring. How can I do that using a batch file.
for ex. I want to find out the version info of "myfile-<version>-def.jar" where substring availabe to me as an input is "myfile".

See More: Substring in file name in a directory.

Report •


#1
November 23, 2009 at 13:08:14
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d myfile*.jar') do (
for /f "tokens=2 delims=-" %%i in ("%%~Na") do (
set jarver=%%i
)
echo %%a jarver is !jarver!
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
November 23, 2009 at 22:31:43
Thanks a lot. It worked.

Report •

Related Solutions


Ask Question