Q:

How can I use special characters for making folder in batch file?

@echo off
setlocal EnableDelayedExpansion

set "folder=C:\Test\Test01\Test02\Test03\Test04\!!Test05\Test06"

md %folder%\Final

echo %folder%
pause

This will create in C:\Test\Test01\Test02\Test03\Test04\Test05\Test06\Final.
Result should be like C:\Test\Test01\Test02\Test03\Test04\!!Test05\Test06\Final.
How can I use special characters (!!Test05) for making folder in batch file?

A:

When delayed expansion is enabled, exclamation marks are lost when stating them literally or when expanding normal %-variables. Toggle delayed expansion and read affected variables with surrounding ! only to overcome this:
@echo off
setlocal DisableDelayedExpansion

rem // Delayed Expansion is disabled, so literal exclamation marks are maintained:
set "folder=C:\Test\Test01\Test02\Test03\Test04\!!Test05\Test06"

setlocal EnableDelayedExpansion
rem /* Delayed Expansion is enabled, so do not expand variables with `%`,
rem    or you will lose exclamation marks: */
md "!folder!\Final"
endlocal

rem /* Delayed Expansion is disabled, variables can be expanded with `%`,
rem    without losing exclamation marks: */
echo "%folder%"
endlocal

