Skip to content

Instantly share code, notes, and snippets.

@PSingletary
Created December 12, 2017 14:30
Show Gist options
  • Save PSingletary/5239e6813de60c8057e6ccb72d7a804f to your computer and use it in GitHub Desktop.
Save PSingletary/5239e6813de60c8057e6ccb72d7a804f to your computer and use it in GitHub Desktop.
convert entries in PATH to 8.3 format to gain more character space
REM http://stackoverflow.com/questions/4405091/how-avoid-over-populate-path-environment-variable-in-windows
@echo off
SET shortpath=%PATH%
echo "Old PATH documented in C:\_admin\OLDPath.txt"
echo %shortpath%
echo %shortpath% > C:\_admin\OLDPath.txt
echo --
echo "Directories not found, documented in C:\_admin\PATH_folders_not_found.txt"
echo --
setlocal EnableDelayedExpansion
SET TempPath="%shortpath:;=";"%"
SET var=
FOR %%a IN (%TempPath%) DO (
IF exist %%~sa (
SET "var=!var!;%%~sa
) ELSE (
echo %%a does not exist >> C:\_admin\PATH_folders_not_found.txt
)
)
echo --
echo "Shortened PATH documented in C:\_admin\NEWPath.txt"
echo --
echo !var:~1!
echo !var:~1! > C:\_admin\NEWPath.txt
echo --
echo "Open C:\_admin\NEWPath.txt, Open regedit, Navigate to HKLM\System\CurrentControlSet\Control\Session Manager\Enviroment, Dobule click on Path, copy in contents of C:\_admin\NEWPath.txt, Click OK, reboot PC, Validate change."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment