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

  • SEARCH
  • Home
  • 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 7562595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:26:50+00:00 2026-05-30T13:26:50+00:00

I have a hard time understanding the following batch script: @echo off echo b>b.txt

  • 0

I have a hard time understanding the following batch script:

@echo off
echo b>b.txt
for /f %%A in ('echo b.txt b.txt') do (
    echo %%A
    if not exist %%A (
        echo does not exist.
    ) else (
        echo %%A exist.
    )
)

In the beginning, I make sure that a file “b.txt” exists, and then I would expect the loop to output twice the name of this file, and that it exists. However, the actual output that I get is:

b.txt
does not exists

Can someone explain this behavior?

  • 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-05-30T13:26:51+00:00Added an answer on May 30, 2026 at 1:26 pm

    Just as suggestion you may try to assign file name to variable just to make sure you reference exactly same thing in both statements, like this:

    set file=b.txt
    echo b>%file%
    for /f %%A in ('echo %file% ^& echo %file%') do (
        echo [%%A]
        if  not exist %%A (
            echo [%%A] does not exist.
        ) else (
            echo [%%A] exist.
        )
    )
    

    I also removed echo off so you would see expansion output, and put brackets around %%A to see it’s boundary

    Edit: some addtional troubleshooting:
    I would probably start building the script up from command line, changing only only one thing at a time and see where it breaks.

    if b.txt exist echo Exists

    If it works then

    for /f %A in ('echo whatever') if b.txt exist echo Exists

    and so on, up to

    for /f %A in ('echo b.txt ^&echo b.txt') do (if exist %A (echo %A exists) else (echo not exists))
    

    You could also use different for variant (although I cannot see how it could make a difference):

    for %A in (b.txt b.txt) do (if exist %A (echo %A Exists) else (echo not exists))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hard time understanding the layout tutorial. I am not able to
I'm just beginning to use CKEditor, but have a hard time understanding the plugins
I have been having a hard time understanding how to use a singleton to
I'm using Omron CP1L PLC and program with CX-programmer. I have hard time understanding
I have solved #103 and #105, but I have a hard time understanding #106
I'm having a hard time understanding this regex stuff... I have a string like
I having hard time understanding importance and benefits of Annotations and so have two
I'm having a hard time in understanding the unexpected output for the following program:
Might be just me, but I have a hard time understanding how to secure
What exactly is MetaData SQLAlchemy? I have a hard time understanding this. And what

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.