使用“路径变量"的所有条目的FOR进行批处理脚本打印. [英] Batch scripting printing with a FOR all the entries of the "Path variable"
问题描述
我正在尝试使用Batch line命令来解析我的"Path"环境变量.我想要实现的是将"Path"变量的每个子字符串打印在不同的行上.
I'm trying to parse my "Path" environment variable with a Batch line command. What I would like to achieve is having each substring of the "Path" variable to be printed on a different line.
以下,我可以使用分号;"打印路径"的每个标记.作为分隔符:
With the following, I can print each token of the "Path" using semicolon ";" as a separator :
For /F "tokens=* delims=;" %i in ("%Path%") do @echo %i
但是我的输出是C:\ blabla1 \ bin C:\ blabla2 \ bin C:\ blabla3 \ bin C:\ blabla4 \ bin.我想保留回车符,但我无法做到这一点.
but my output is C:\blabla1\bin C:\blabla2\bin C:\blabla3\bin C:\blabla4\bin . I would like to concat the carriage return, but I'm not able to do that.
有什么建议吗?谢谢
p.s.我想在一个命令行中实现这一目标,避免使用保存在单独的.bat文件中的脚本
p.s. I would like to achieve this within a single command line, avoiding to use a script saved in a separate .bat file
推荐答案
Call :Entry %Path%
GoTo :EOF
:Entry
For /F "Tokens=1,* Delims=;" %%i In ("%1") Do (
Set Entry=%%i
Set Remaining=%%j
)
Rem Do something with %Entry% ...
If Defined Remaining Call :Entry %Remaining%
GoTo :EOF
这篇关于使用“路径变量"的所有条目的FOR进行批处理脚本打印.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!