Solved Batch File Delete all character before certain string

July 4, 2016 at 01:25:28
Specs: Windows 8.1
Hi,

I have extract service description like:
sc qc %line1% | find "BINARY_PATH_NAME",
it return as follow:
" BINARY_PATH_NAME : "C:\Program Files\..." --temporary-file="C:\MyFolder\try.txt" service1"

My question is, how can I extract out only portion of "C:\MyFolder\try.txt"

Thank you.

message edited by azleen


See More: Batch File Delete all character before certain string

Report •


#1
July 8, 2016 at 10:30:24
✔ Best Answer
Well, if the equals sign is guaranteed, you could just go with:
for /f "tokens=2 delims==" %%a in ('sc qc %line1% ^| find "BINARY_PATH_NAME"') do ^
echo %%a

How To Ask Questions The Smart Way


Report •

#2
July 11, 2016 at 23:35:10
Thank you Razor2.3
it's simplified the line as per I wanted.

Another silly question,

from the command result above :
"C:\MyFolder\try.txt" service1

how do I set 2 new variables as a result like:
var1 = C:\MyFolder
var2 = try.txt

Thank you.


Report •

#3
July 12, 2016 at 05:55:34
That's less simple. If you can cheat a little bit with var1, you could try:
set var1=
for /f "tokens=2 delims==" %%a in ('sc qc %line1% ^| find "BINARY_PATH_NAME"') do (
  for %%b in (%%a) do if not defined var1 (set var1=%%~DPb&set var2=%%~NXb)
)

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
July 12, 2016 at 18:46:29
thank you sir!

appreciate it.


Report •

Ask Question