The regular escape character in dos batch files is ^ . However, for percent, % , the delimiter for variables, the escape should double the percent: %%cd%% . Things change when using parameter extensions inside a for loop. Instead of %%~dpnx0 emitting %~dpnx0 , since it goes beyond the loop, it performs a replacement emitting D:\Scripts\foo.py
Here's a demo of a batch file:
@echo off echo This is a pipe: ^| echo Use this var for the current directory: %%cd%% echo Use this to echo full path of running batch file: %%~dpnx0 for %%a in (foo.py baz.py) do ( echo @python %%~dpnxa ^> %%~na.bat )
Here are the results I get:
This is a pipe: | Use this var for the current directory: %cd% Use this to echo full path of running batch file: %~dpnx0 @python d:\Scripts\foo.py > foo.bat @python d:\Scripts\baz.py > baz.bat
But this is what I want:
This is a pipe: | Use this var for the current directory: %cd% Use this to echo full path of running batch file: %~dpnx0 @python %~dpnxa > foo.bat @python %~dpnxa > baz.bat
I tried to double, triple and quadruple the percentage, as well as navigate through all, all without success.
matt wilkie
source share