Delims in For loop not working as expected

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Delims in For loop not working as expected

#1 Post by PaperTronics » 27 Jun 2017 23:47

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!

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Delims in For loop not working as expected

#2 Post by npocmaka_ » 27 Jun 2017 23:50

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

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Delims in For loop not working as expected

#3 Post by PaperTronics » 28 Jun 2017 00:44

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:

Post Reply