Windows CMD: PATH Variable – Add To PATH – Echo PATH

PATH is an environment variable that specifies a set of directories, separated with semicolons (;), where executable programs are located.

In this note i am showing how to print the contents of Windows PATH environment variable from the Windows command prompt.

I am also showing how to add a directory to Windows PATH permanently or for the current session only.

Cool Tip: List environment variables in Windows! Read More →

Echo Windows PATH Variable

Print the contents of the Windows PATH variable from cmd:

C:\> path

– or –

C:\> echo %PATH%

The above commands return all directories in Windows PATH environment variable on a single line separated with semicolons (;) that is not very readable.

To print each entry of Windows PATH variable on a new line, execute:

C:\> echo %PATH:;=&echo.%

Cool Tip: Set environment variables in Windows! Read More →

Add To Windows PATH

Warning! This solution may be destructive as Windows truncates PATH to 1024 characters. Make a backup of PATH before any modifications.

Save the contents of the Windows PATH environment variable to C:\path-backup.txt file:

C:\> echo %PATH% > C:\path-backup.txt

Set Windows PATH For The Current Session

Set Windows PATH variable for the current session:

C:\> set PATH="%PATH%;C:\path\to\directory\"

Set Windows PATH Permanently

Run as Administrator: The setx command is only available starting from Windows 7 and requires elevated command prompt.

Permanently add a directory to the user PATH variable:

C:\> setx path "%PATH%;C:\path\to\directory\"

Permanently add a directory to the system PATH variable (for all users):

C:\> setx /M path "%PATH%;C:\path\to\directory\"

Info: To see the changes after running setx – open a new command prompt.

Was it useful? Share this post with the world!

11 Replies to “Windows CMD: PATH Variable – Add To PATH – Echo PATH”

  1. Hello, once I have backed up my path how do I restore it from the path_backup file I wrote?

  2. Nevermind, I could do it by using: set %PATH%=<path-backup.txt

  3. set %PATH%=<path-backup.txt
    this didn't work for me

    1. Dhruv Singh Bhadauriya says: Reply

      The bracket is meant to face like this >

      1. Vikrant Singh says: Reply

        lmao

  4. Pretty sure there is a better way to do this but you can copy the text in your backup file then : setx (/M) path “”

  5. setx /M is giving me error. I can only assign path to user PATH variable

  6. This worked for me in Windows10, adding Clearcase\bin
    setx MPATH ^%PATH^%:”C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\bin”

  7. Oh man am I lucky I backed up both the System and User Environment Variables because I was messing around in Powershell and typed
    “`ps
    setx Path $env:path;\C:\Users\name\Desktop\testdir
    “`
    which saved both the System and User Path variable together, and that of course exceeded 1024 characters. And because the User Path is listed second, it didn’t even make it there before cutting off.

  8. Thanks so much for your hacks and tips –
    I searched all day to understand a way to list out the %path% into single lines. :
    C:\> echo %PATH:;=&echo.%
    Now, Would you kindly share how to PRINT this listing to .txt file
    which I can only make appear on the screen?
    I’ve tried many different combinations of things, and none have worked yet.
    Thx again

  9. Be careful with this: it seems the setx command crops its input to 1024 characters!

Leave a Reply