JSI Tip 9055. What command will return the folders in my PATH, one per line?
February 14, 2005
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.
About the Author
You May Also Like