How to extract string value and construct contact string in Windows Batch

Could you help with below please.


- In Windows batch, would like to check a folder with specific file pattern e.g *.sif. We might find 1 or more files. Files are in sif extension but it just a text file in xml style. (not binary)

- Look for string "PROCESS_NAME" and get the value of of it. E.g PROCESS_NAME="TEST Workflow 1"

- Loop through all files in the directory and get all values. E.g. if we find "TEST Workflow 1" and "TEST Workflow 2" etc etc.

- Variable should be set like below.
e.g workflow_list='TEST Workflow 1','TEST Workflow 2','TEST Workflow 3'

If it is easy in powershell, we can do that, but is it easy to bring the value back to batch variable please

Have attached two sample files.

Thanks in advance :)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Should be doable in a BAT script, working something up...

enthuguyAuthor Commented:
Thanks a lot Bill :)
enthuguyAuthor Commented:
Hi Bill
sorry, based on the new finding the way powershell accepts
can we surround with escape char ` please

workflow_list=`'TEST Workflow 1`'`,`'TEST Workflow 2`'`,`'TEST Workflow 3`'
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Bill PrewIT / Software Engineering ConsultantCommented:
What do you want the actual DOS environment variable to contain?  Do you really want all those varied quotes?

`'TEST Workflow 1`'`,`'TEST Workflow 2`'`,`'TEST Workflow 3`'

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
If I take what you said literally, here is a BAT script that does what you asked for, adjust the path near the top as needed and test there.

@echo off
setlocal EnableDelayedExpansion

rem Define files to process
set BaseDir=B:\EE\EE29073755\*.sif

rem Specify characters to place around each match found in list variable
set Quote=`'

rem Specify characters to place between each match found in list variable
set Delim=`,

rem Clear out result list variable
set WorkflowList=

rem Search all files for element we want, extract part to right of equal sign
for /f "tokens=1* delims==" %%A in ('findstr /i /r /c:"\<PROCESS_NAME=" "%BaseDir%"') do (
    rem Add to list
    if defined WorkflowList (
        set WorkflowList=!WorkflowList!%Delim%%Quote%%%~B%Quote%
    ) else (
        set WorkflowList=%Quote%%%~B%Quote%

rem Display list
echo %WorkflowList%

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
enthuguyAuthor Commented:
Thanks a lot bill, really appreciate ur help
enthuguyAuthor Commented:
Thanks once again Bill, that was a timely help and it worked perfectly for me
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.