help me with dos find string using substring

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jagadish
Posts: 1
Joined: 23 Nov 2015 10:53

help me with dos find string using substring

#1 Post by jagadish » 23 Nov 2015 11:46

Hi Everyone,

I have file (filename.txt) which contains

ProductABC_Test.txt
ProductDEF_Test.txt
ProductHIG_Test.txt
ProductIJK_Test.txt

I will be getting a variable passed (ex: product=ABC which will be substring of ProductABC_Test.txt). So I need to fetch the correct test name (ProductABC_Test.txt) from the filename.txt.

I have tried like below -

SETLOCAL ENABLEEXTENSIONS

::@echo off
set product=ABC

SETLOCAL EnableDelayedExpansion

for /F "tokens=*" %%A in (filenames.txt) do (
Set str=%%A
echo %str%

if NOT %str%==!%str:product=% (
set test_suite=!test_suite! %%A
)else (
echo
)
)
ENDLOCAL
echo %test_suite%


But I am not getting the right result. Please help.


Post Reply