Last active
January 11, 2020 05:34
-
-
Save examinedliving/6251286 to your computer and use it in GitHub Desktop.
Split Windows Path variable (or anything else) into seperate lines to view easily from command line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: This assumes you are running from command line. To run from batch script, add the next commented out line to the top of | |
:: your batch file. Also, in a batch file the % sign before the i should be doubled, .e.g. %%i. | |
:: batch file only - remove preceeding semicolons from the next line and insert in batch file. | |
:: SETLOCAL ENABLEDELAYEDEXPANSION | |
:: from command prompt only - add the next line | |
cmd /v:on | |
for /f "tokens=*" %i in ("%path%") do set a=%i && set b=!a:;=^&echo.! | |
echo %b% | |
:: output displays a single column of (in this case) path names. | |
:: Can be used to split other items into a column from the command line. Just put whatever | |
:: delimiter you want to split by after the `a:` where the semicolon is now in the code above. |
Here's a way that works:
@echo off
set node_path=!PROGRAMFILES!\nodejs
for %%A in ("%path:;=";"%") do (
echo "%%~A"
echo %%~A|find /i "node" >nul
if not errorlevel 1 (
set node_path=%%~A
)
)
echo "Node-Path: %node_path%"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please clarify the comment ":: from command prompt only - add the next line"
because line 8 is empty
and line 9 is already added;
I find this not worky.