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

Hi
Could you help with below please.

Scenario:

- 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 :)
wf_nxg_application_error_handler_wor.txt
wf_nxg_publish_error_republish_batch.txt
enthuguyAsked:
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 PrewCommented:
Should be doable in a BAT script, working something up...


»bp
0
enthuguyAuthor Commented:
Thanks a lot Bill :)
0
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`'
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Bill PrewCommented:
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


»bp
0
Bill PrewCommented:
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


»bp
1

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
0
enthuguyAuthor Commented:
Thanks once again Bill, that was a timely help and it worked perfectly for me
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.