0

I need to brake a variable into two base on slash \ delimiter and then set the second value to a variable and print it in a file. Here is my code

set string=somestuff\needthis\ok

If NOT "%string%"=="%string:somestuff=%" (
    for /f "tokens=1,2 delims=\" %%a in ("%string%") do (set "mystuff=%%b"
    echo %mystuff% >> myfile.txt
    )
) else (
    echo No >> myfile.txt
)

Problem Point : if I directly echo %%b then that will be printed in myfile.text but if I assign it to variable and then try to echo the variable value it don't print anything.

RishiKesh Pathak
  • 2,122
  • 1
  • 18
  • 24
  • 5
    You need to `SETLOCAL ENABLEDELAYEDEXPANSION` and then `ECHO !mystuff!` instead – Compo Mar 15 '17 at 09:50
  • @Compo you're 21 seconds faster then me..... –  Mar 15 '17 at 09:51
  • duplicate: [for loop in batch file](http://stackoverflow.com/q/6680409/995714), [windows batch files: setting variable in for loop](http://stackoverflow.com/q/5615206/995714) – phuclv Mar 15 '17 at 10:12
  • 1
    Possible duplicate of [for loop in batch file](http://stackoverflow.com/questions/6680409/for-loop-in-batch-file) – aschipfl Mar 15 '17 at 18:06

0 Answers0