Skip to content

Instantly share code, notes, and snippets.

@pavel-a
Created May 20, 2018 23:47
Show Gist options
  • Save pavel-a/9cfdab4244c7bbbcaf9f32e81dfbaf01 to your computer and use it in GitHub Desktop.
Save pavel-a/9cfdab4244c7bbbcaf9f32e81dfbaf01 to your computer and use it in GitHub Desktop.
Windows path sanitize (de-space, shorten)
: Pass path to sanitize as arg 1
@echo off
echo Original path=[%~1]
call :chkspaces "%~1"
if /I NOT "%_sp%" == "%~1" call :shrt "%~1"
echo uglified=[%_sp%]
goto :EOF
:chkspaces
set _sp=%1
set _sp=%_sp: =%
goto :EOF
:shrt
echo arg=[%1]
set _sp=%~s1
goto :EOF
: Shortenize current path. To return, type popd.
@echo off
echo [%cd%]
call :shrt "%cd%"
goto :EOF
:shrt
echo arg=[%1]
set _sp=%~s1
echo short=[%_sp%]
pushd "%_sp%"
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment