JSI Tip 9055. What command will return the folders in my PATH, one per line?

Jerold Schulman

February 14, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


Making use of Environment Variable string substitution syntax, and the FOR %variable IN (set) DO command command, you can use the command-line, or a batch, to display the folders in your %PATH%, one per line:

Command-line

for %f in ("%PATH:;=" "%") do @echo %f

Batch

for %%f in ("%PATH:;=" "%") do @echo %%f

If you wish to also strip the encapsulating quote marks ("), you can add parameter parsing:

Command-line

for %f in ("%PATH:;=" "%") do @echo %~f

Batch

for %%f in ("%PATH:;=" "%") do @echo %%~f

Examples:

If your %PATH% contains:

C:Program FilesWindows Resource KitsTools;C:WIN_ONE;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:UTIL


Typing for %f in ("%PATH:;=" "%") do @echo %f would return:

"C:Program FilesWindows Resource KitsTools""C:WIN_ONE""C:WINDOWSsystem32""C:WINDOWS""C:WINDOWSSystem32Wbem""C:UTIL"

while typing for %f in ("%PATH:;=" "%") do @echo %~f would return:

C:Program FilesWindows Resource KitsToolsC:WIN_ONEC:WINDOWSsystem32C:WINDOWSC:WINDOWSSystem32WbemC:UTIL

NOTE: What is happening with ("%PATH:;=" "%"):

1. The leading " inserts a quote mark at the beginning of the set.

2. The %PATH:;=" "% replaces all ;s with " ", defining the end of each folder path and the beginning of the next.

3. The trailing " inserts a quote mark at the end of the set.



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like