Skip to content

Instantly share code, notes, and snippets.

@Spinarooni
Created September 14, 2015 18:39
Show Gist options
  • Save Spinarooni/4a3c874419a01f24f1b2 to your computer and use it in GitHub Desktop.
Save Spinarooni/4a3c874419a01f24f1b2 to your computer and use it in GitHub Desktop.
Script to compress file paths in PATH variable in Windows OS. Use when path length is being exceeded. Does not update the actual OS path but allows you to copy and paste it.
@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