Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:05:25+00:00 2026-06-15T10:05:25+00:00

The usual escape character in dos batch files is caret, ^ . However for

  • 0

The usual escape character in dos batch files is caret, ^. However for percent, %, the delimiter for variables, the escape is to double up the percents: %%cd%%. Things change when using parameter extensions inside a for loop. Instead of %%~dpnx0 emitting %~dpnx0, as it will outside the loop, it carries out the substitution, emitting D:\Scripts\foo.py.

Here’s a batch file demonstration:

@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
  )

These 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’ve tried doubling, tripling, and quadrupling the percents as well is interspersing carets throughout, all without success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:05:26+00:00Added an answer on June 15, 2026 at 10:05 am

    It is impossible to prevent a FOR variable expression from expanding. If a FOR is in effect with variable X defined, then the FOR expansion phase will always expand %X.

    But you can hide the percent behind another FOR variable 🙂

    The following gives the result you are looking for:

    @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 %%P in (%%) do for %%A in (foo.py baz.py) do (
      echo @python %%P~dpnxA ^> %%~nA.bat
    )
    

    FOR variables have global scope (though they are only accessible within the DO clause). This can lead to an insidious problem. Any time you have a subroutine that uses a percent literal within a FOR loop, then you are at risk of unintended results! A FOR statement issued before your CALL can influence the results of a FOR DO clause within your CALLed routine.

    @echo off
    for %%) in (Yikes!) do call :test
    exit /b
    
    :test
    echo This works outside loop (confidence = 100%%)
    for %%A in (1) do echo This does not work inside loop (confidence = 100%%)
    for %%P in (%%) do for %%A in (1) do echo This works inside loop (confidence = 100%%P)
    exit /b
    

    Here is the output

    This works outside loop (confidence = 100%)
    This does not work inside loop (confidence = 100Yikes
    This works inside loop (confidence = 100%)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usual method of applying mathematics to variables is a * b Is it able
The usual method of URL-encoding a unicode character is to split it into 2
I am having the usual errors within header files, as listed below. Error 54
The usual way to create a geometry column is AddGeometryColumn , however I have
The usual way to resolve lnk involve using WShell.WshShortcut or IShellLink that way :
The usual alpha symbol for regular expressions \w in the .NET Framework matches alphanumeric
The usual way to assign color box functionality on a link is like this:
The usual pattern for a singleton class is something like static Foo &getInst() {
A usual way to put, for example a menu tab with background is as
as usual I'm working with my messed up database and I found that there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.