Given the following for loop from a batch file, why is this only printing A? I have also tried with "tokens=1*"
set str=A/B/C/D/E/F
for /F "delims=/" %%S in ("%str%") do (
echo %%~S
)
The delims option defines the delimiters to split each line into seperate tokens. The tokens itself can be accesses by succesive parameters.
set str=A/B/C/D/E/F
for /F "tokens=1,2,3,4,5 delims=/" %%S in ("%str%") do (
echo %%~S %%T %%U %%V %%W
)
This will split each line, but you want to handle A/B/C/D/E/F as seperate lines.
This can be done by injecting linefeeds
set LF=^
REM ** Two empty lines are required
setlocal EnableDelayedExpansion
set "str=A/B/C/D/E/F"
for %%L in ("!LF!") DO set "str=!str:/=%%~L!"
for /F "delims=/" %%S in ("!str!") do (
echo %%~S
)
The line for %%L in ("!LF!") DO set "str=!str:/=%%~L!" replaces / with linefeeds