Parse PATH using FOR / F in a BAT script

I need to parse the% PATH% list in a .BAT script, but I'm not very lucky with paths containing spaces.

for %%a in (%PATH%) do @echo %%a

The above analyzes are for spaces (by default), but I need to parse in half-columns. I try to use this, but it causes me an error:

for /f "tokens=* delims=;" %%a in (%PATH%) do @echo %%a

The result is one line: "The system cannot find the file C: \ Windows \ system32."

I am sure that I am missing something very simple, but any help would be greatly appreciated. TY!

+3
source share
2 answers
SET TempPath="%Path:;=";"%"
FOR %%a IN (%TempPath%) DO echo.%%~a
+9
source

, - , FOR. :

@ECHO OFF
SET TEMPPATH=%PATH%
:PARSE_START
IF "%TEMPPATH%"=="" GOTO EXIT
FOR /F "tokens=1* delims=;" %%a in ("%TEMPPATH%") Do ECHO %%a
FOR /F "tokens=1* delims=;" %%a in ("%TEMPPATH%") Do SET TEMPPATH=%%b
GOTO PARSE_START
:EXIT
+2

Source: https://habr.com/ru/post/1773233/


All Articles