Page 1 of 1

Delims in For loop not working as expected

Posted: 27 Jun 2017 23:47
by PaperTronics
Hey guys!

I'm having a problem using delims in the For loop.

Code: Select all

@echo off
Setlocal EnableDelayedExpansion
For /f "tokens=* delims=:" %%A IN (DataFile.Tronic) DO (
   Set File1=%%A
   Set File2=%%B
   Set File3=%%C
   )
pause
Echo %File1%
Echo %File2%
Echo %File3%
pause


DataFile.Tronic contains the following data:

Code: Select all

E3455890.bat:Status=RootNone:9475d01.xml:


Yet the output on the cmd console is

Code: Select all

E3455890.bat:Status=RootNone:9475d01.xml:
%B
%C



I don't understand why the delims don't separate the variables.

Any help is greatly appreciated!

Re: Delims in For loop not working as expected

Posted: 27 Jun 2017 23:50
by npocmaka_
You need to point out the tokens too:

Code: Select all

@echo off
Setlocal EnableDelayedExpansion
For /f "tokens=1,2* delims=:" %%A IN (DataFile.Tronic) DO (
   Set File1=%%A
   Set File2=%%B
   Set File3=%%C
   )
pause
Echo %File1%
Echo %File2%
Echo %File3%
pause

Re: Delims in For loop not working as expected

Posted: 28 Jun 2017 00:44
by PaperTronics
Thanks npocmka! It's working as a charm now!

Don't know why I was so dumb not to find this mistake in my code :mrgreen: