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 7657691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:05:21+00:00 2026-05-31T13:05:21+00:00

I think I ran into a bug in Window’s batch scripting. I cannot set

  • 0

I think I ran into a bug in Window’s batch scripting.

I cannot set variables that are in an expanded if statement.

Here is an isolated part of my script:

@echo off

set success=1
set Version=12345
set Target=Client
set Type=456
set dir=
set zip=

if "%Version%"=="" set success=0
if "%Type%"=="" set success=0

if 1==1 set test=42

if %success%==1 (
    set test2=57005
    if "%Target%"=="Client" (
        set dir=ModName v%Version%
        set zip=ModName v%Version% %Type%.zip
        echo Version: %Version%
        echo    Type: %Type%
        echo.
        echo  Target: %Target%
        echo     dir: %dir%
        echo     zip: %zip%
        echo.
        echo    test: %test%
        echo   test2: %test2%
    )
) else (
    echo Not successful.
)

This is the output from a brand new instance of cmd:

C:\Users\RandomClown\Desktop>test.bat
Version: 12345
   Type: 456

 Target: Client
    dir:
    zip:

   test: 42
  test2:

What you should notice is that the single line if statement correctly sets stuff.
The multiline if will perform anything that is NOT a set. I dont think I missed anything.
Also, the multiline if statement is correctly executing the right lines, as the else ( echo Not successful. ) lines did not execute.

Why did the lines not execute?

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

    You missed something 😉

    cmd expands variables when commands are parsed, not when they are run. It so happens that an if or for statement with a block ( ... ) (or actually any block) counts as a single command in that case. So when you set variables inside a block and try using them in the same block there are no variables anymore – they were replaced by the values the variables had before the block even executed.

    Stick a

    setlocal enabledelayedexpansion
    

    at the start of your batch file and use !zip! instead of %zip%. See help set for a detailed discussion of the problem.

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

Sidebar

Related Questions

I think i ran into a bug, it seems that EF is not handling
We ran into a bug in our product caused by the fact that for
I ran into a bug I have trouble explaining. Now that I found the
I ran into this today and the only thing I can think is that
Possible Duplicate: Reversing a regular expression in python I think I ran into a
I'm new to anonymous classes, and today I think I ran into the first
A co-worker ran into an interesting issue today, and while I think the actual,
I ran into the situation that I need a way to edit the data
Recently I ran into a mysterious problem that IE (6-8) is keeping throwing me
Just ran into a bit of code that wasn't doing what I thought it

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.