Batch file below:
@echo off
set filelocation=C:\\Users\\myself\\Documents\\This&That
cd %filelocation%
echo %filelocation%
pause
give
Unlike Jeb, I don't think you need delayed expansion to use the variable in a safe way. Proper quotation could suffice for most use:
@echo off
SETLOCAL EnableExtensions DisableDelayedExpansion
set "filelocation=C:\Users\myself\Documents\This&That"
cd "%filelocation%"
echo "%filelocation%"
rem more examples:
dir /B "%filelocation%\*.doc"
cd
echo "%CD%"
md "%filelocation%\sub&folder"
set "otherlocation=%filelocation:&=!%" this gives expected result
SETLOCAL EnableDelayedExpansion
set "otherlocation=%filelocation:&=!%" this gives unexpected result
ENDLOCAL
pause
Moreover, this is universal solution while delayed expansion could fail in case of ! exclamation mark in processed string (e.g. last set command above).