I need to parse the %PATH% list in a .BAT script, but I'm not having much luck with paths that contain spaces.
for %%a in (%PATH%) do @echo %%a
The above parses on spaces (default), but I need to开发者_C百科 parse on semi-colons. I'm trying to use this but it's throwing 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'm sure I'm missing something very basic but any help would be greatly appreciated. TY!
SET TempPath="%Path:;=";"%"
FOR %%a IN (%TempPath%) DO echo.%%~a
To do this correctly, you need something more complicated than a simple FOR. Try the following in a batch file:
@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
精彩评论