In Windows, when each of the PATH variables need to be listed on a single line then the command to be used is for %a in ("%path:;=";"%") do @echo %~a
can be executed.
I don't understand, what does "%path:;=";"%"
do?
In Windows, when each of the PATH variables need to be listed on a single line then the command to be used is for %a in ("%path:;=";"%") do @echo %~a
can be executed.
I don't understand, what does "%path:;=";"%"
do?
It takes the value of the %path%
variable and substitutes each occurrence of ;
character with ";"
. For more details see the output of set /?
in command prompt.
In windows batch files, you can do string substitution in variables using the syntax
%var:search=replace%
In your case, the variable is path
, the search is ;
and the replacement is ";"
v ......... search
%path:;=";"%
^^^ ..... replace
That way each semicolon in the variable contents is replaced by the same semicolon, but with a double quote in each side. Including an starting and ending quotes around the expression
"%path:;=";"%"
every semicolon delimited element in the path
variable is now quoted
c:\windows ; c:\windows\system32 ; c:\windows\system32\wbem ; c:\other folder
v vvv vvv vvv v
"c:\windows";"c:\windows\system32";"c:\windows\system32\wbem";"c:\other folder"
Now there is a list of quoted strings separated by a semicolon delimiter.
This string is processed by a for
command that will process each delimited element storing it inside the %a
replaceable parameter and executing the code inside the do
clause for each value, echoing to console the content of the replaceable parameter without quotes (%~a
)
All this to be able to enumerate the different directories in the path
variable because it probably will contain other characters (ex. spaces) that are handled as delimiters by the for
command.