Skip to content

Instantly share code, notes, and snippets.

@ryanwischkaemper
Created December 4, 2015 15:21
Show Gist options
  • Save ryanwischkaemper/19918bcb3c216b670298 to your computer and use it in GitHub Desktop.
Save ryanwischkaemper/19918bcb3c216b670298 to your computer and use it in GitHub Desktop.
This will parse your %PATH% environment variable and convert each directory to its shortname equivalent and then piece it all back together. Use the output to replace current PATH
@echo off
SET MyPath=%PATH%
echo %MyPath%
echo --
setlocal EnableDelayedExpansion
SET TempPath="%MyPath:;=";"%"
SET var=
FOR %%a IN (%TempPath%) DO (
IF exist %%~sa (
SET "var=!var!;%%~sa"
) ELSE (
echo %%a does not exist
)
)
echo --
echo !var:~1!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment