在 CMD 中,当我输入时PATH
,输出:
Path=C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;
我需要用新行分割每个路径,然后输出变成:
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\
C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\
C:\Windows\system32
C:\Windows
我可以使用 PowerShell 来执行此操作$Env:Path.Split(';')
,或者从 CMD 调用它powershell -c "$Env:Path.Split(';')"
。
我如何在 CMD 中自行执行此操作?
我试过:
For /F "Tokens=1* Delims=;" %A in ('%PATH%') do @Echo %A %B
For /F "Tokens=1* Delims=;" %A in (%PATH%) do @Echo %A %B
给出错误:\Intel\Intel(R) was unexpected at this time.
谢谢T3RR0R。
@For %G in ("%PATH:;=" "%")Do @Echo(%~G
答案1
您可以使用 FOR 循环。将其保存到 BATCH 文件中(例如分割路径)
@echo off
rem Get the PATH variable
set "PATH_STR=%PATH%"
rem Use FOR loop to split and print each path on a new line
for %%a in ("%PATH_STR:;=" "%") do (
echo %%~a
)