1

Here is my batch file, try.cmd:

for /f "delims=;" %%d in ("%PATH%") do echo %%d

Curiously, only the first directory in the path got printed, then the loop stopped. How do I get to loop over all directories in the path?

2

3 Answers 3

3

You mean

@ECHO OFF
SETLOCAL
ECHO %path:;=&ECHO(%

?

Your version doesn't work because for /f is required to invoke the delims= facility, but that means that there's only one input "line"; the for command will iterate through a sequence, but that means there's no delims available...

Sign up to request clarification or add additional context in comments.

Comments

2
@SETLOCAL
@ECHO OFF
SET "P=%PATH%"
:EXTRACT_LOOP
for /f "tokens=1* delims=;" %%p in ("%P%") do (echo %%p & SET P=%%q)
IF NOT "%P%" == "" GOTO :EXTRACT_LOOP

There might be another smart way.

Comments

0

Try this:

Printf.bat

@echo off
:loop
Echo %~1
shift /1
if "%~1" NEQ "" goto loop

Cmd

C:\>Printf.bat 1 2 3 4 5 6
1
2
3
4
5
6

C:\>set test=A;B;C;D
C:\>Printf.bat %test:;= %
A
B
C
D

C:\>Printf.bat %Path:;= %
...

C:\>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.