2 Methods to Split PATH Environment Variable Into Lines on Windows

2 Methods to Split PATH Environment Variable Into Lines on Windows

The PATH environment variable on Windows is a crucial system variable that specifies the directories where the operating system looks for executable files. Managing this variable is essential for system administrators and developers, especially when they need to modify or troubleshoot the system's behavior. Occasionally, you may need to split this variable into individual lines to view or manipulate its contents. This tutorial provides 2 methods how to split PATH environment variable into lines on Windows.

Method 1 - CMD

To split the PATH environment variable into separate lines using the Command Prompt (CMD), use the following command:

echo.%PATH:;= & echo.%

The %PATH:;= part replaces each semicolon (;) in the PATH variable with a newline character, effectively separating the directories onto different lines. The echo command then prints each separated path on a new line.

Output example:

C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
...

Method 2 - PowerShell

In PowerShell, we can split the PATH environment variable into lines using the following command:

$env:PATH -split ";"

The command uses the -split option to split the PATH variable into an array of substrings, using the semicolon (;) as the delimiter.

Leave a Comment

Cancel reply

Your email address will not be published.