Adding entries to the PATH persistently (be aware of the 1024 character limit of SETX)
Posted by jpluimers on 2025/01/08
Directly after a new Windows installation, I want to have my cloned git repository of batch files in the PATH persistently so that it gets searched after rebooting or opening a new console window.
At that moment, there is not much of a 1024 PATH character limitation, but be aware about that limit if you try this yourself.
This is my add-current-directory-to-path-at-end.persistent-and-limit-to-1024-characters.bat:
:: https://serverfault.com/questions/664180/can-i-permanently-add-to-path-in-windows-using-batch
:: https://superuser.com/questions/812754/how-to-recover-from-path-being-truncated-to-1024-characters-by-setx
:: global environment
setx PATH "%PATH%;%CD%"
:: local process
:: https://superuser.com/questions/975605/add-current-directory-to-path
set PATH=%PATH%;%CD%
I execute it from within the cloned git directory.
Oh: you need to double-quote the SETX parameters, otherwise you get an error message: “ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).“.
More links than the above ones from the batch file, especially on the 1024 character limitation:
- [Wayback/Archive] windows 7 – Add current directory to PATH – Super User (thanks [Wayback/Archive] Rook, and [Wayback/Archive] ge0rdi)
- [Wayback/Archive] Can I permanently add to PATH in windows using batch? – Server Fault (thanks[Wayback/Archive] Kit Sunde, [Wayback/Archive] Ryan Ries and [Wayback/Archive] Ryan)
- [Wayback/Archive] cmd – How to update PATH variable permanently from Windows command line? – Stack Overflow (thanks [Wayback/Archive] vale4674, [Wayback/Archive] panny and [Wayback/Archive] beresfordt)
- [Wayback/Archive] windows 8 – How to recover from PATH being truncated to 1024 characters by SETX – Super User (thanks [Wayback/Archive] Doug, [Wayback/Archive] Sir Adelaide, and [WaybackSave/Archive] dwillis77)
- [Wayback/Archive] Where are environment variables stored in the Windows Registry? – Stack Overflow (thanks [Wayback/Archive] Brian R. Bondy, [Wayback/Archive] Steve Scheffler, [Wayback/Archive] Jake Nelson, [Wayback/Archive] WalyKu and [Wayback/Archive] Fantastory who wrote a
GETXbatch file more or less the read equivalent ofSETX) - [Wayback/Archive] SetX – Set environment variables – Windows CMD – SS64.com
Queries:
- [WaybackSave/Archive] batch file add current directory to path – Google Suche
- [WaybackSave/Archive] batch file persistently change search path – Sök på Google
- [WaybackSave/Archive] ss64 setx – Google Suche
- [Wayback/Archive] “ERROR: Invalid syntax. Default option is not allowed more than ‘2’ time(s).” – Google Suche
--jeroen






Leave a comment