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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:55:48+00:00 2026-06-02T21:55:48+00:00

I have a for loop in a batch file: @echo off set logpath1=C:\path\to\first\log set

  • 0

I have a for loop in a batch file:

@echo off
set logpath1=C:\path\to\first\log
set logpath2=C:\path\to\second\log
FOR %%G IN (%logpath1% %logpath2%) DO (
  pushd %%G
  pushd ..\
  for %%D IN (%CD%) DO SET "dirname=%%~nxD"
  popd
  echo Will prefix files in %%G with %supername%
  :: do operations.
  popd
)

However, this doesn’t seem to change my working directory. If I run the script from

C:\tmp\path\to

then I get

Will prefix files in C:\path\to\first\log with tmp
Will prefix files in C:\path\to\second\log with tmp 

My purpose is to zip up log files in multiple directories. I’ve tried chdir, cd /d, and &~pd0 instead of %CD%, and searched high and low. Can anyone tell my why this doesn’t work??

  • 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-02T21:55:49+00:00Added an answer on June 2, 2026 at 9:55 pm

    Put

    setlocal enabledelayedexpansion
    

    at the top of your batch file and use !CD! instead of %CD% in the loop. Depending on where %supername% is set you may need to use ! there too.

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

Sidebar

Related Questions

I have following batch file code: @echo off SET INSTALL_PATH=c:\program files\ :ask_again if exist
I have this batch file @ECHO OFF ECHO Please Enter Path of the View,
I have a batch file which initializes variables via SET inside a for loop,
I have the following For loop in a batch file: for /R c:\test\src %%i
I have the following batch script from Wikipedia: @echo off for /R C:\Users\Admin\Ordner %%f
I have a hard time understanding the following batch script: @echo off echo b>b.txt
I would like to set up a simple batch file that would loop through
I have a simple FOR loop inside of a batch file I'm creating that
I have a loop that finds duplicate lines in a .ini file. I can
Reference Iterating arrays in a batch file I have the following: for /f "tokens=1"

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.