Skip to content

Instantly share code, notes, and snippets.

@Brainiarc7
Created December 26, 2016 23:29
Show Gist options
  • Select an option

  • Save Brainiarc7/0df2baf74a9eead7690112b7c1b4b5f2 to your computer and use it in GitHub Desktop.

Select an option

Save Brainiarc7/0df2baf74a9eead7690112b7c1b4b5f2 to your computer and use it in GitHub Desktop.
Windows Batch %PATH% Environment Variable Shortener and Checker
REM In a command shell save output to a text file
REM e.g. C:\Users\myname\Desktop\ PathShortener.cmd > output.txt
REM Review output, then replace current %PATH% variable
REM This handy script was found online, unfortunately the original
REM author isn't credited here.
@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