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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:42:59+00:00 2026-05-24T10:42:59+00:00

I want to create a batch file, batch.bat , that accepts 2 mandatory arguments:

  • 0

I want to create a batch file, batch.bat, that accepts 2 mandatory arguments:

  • %1 represents a path relative to the current directory.
  • %2 represents a filaname.

Assume the current directory is father\me\.

User can use this batch as follows:

  • batch child/grandchild log
  • batch ../brother log

The job description of batch.bat is as follows.

  1. Moves to %1 directory,
  2. Iterates all *.tex file in the %1 directory.
  3. Save the result in the directory before moving.

The following is the incomplete code:

rem batch.bat takes 2 arguments.
cd %1
dir /b *.tex > <original directory>\%2.txt

How to return to the original directory after invoking change directory in DOS batch?

  • 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-24T10:43:00+00:00Added an answer on May 24, 2026 at 10:43 am

    If you want to RETURN to original directory, do the first change with PUSHD and return with POPD. That is, moves to %1 directory must be achieved with

    PUSHD %1
    

    instead of CD %1, and the return is achieved with

    POPD
    

    instead of CD where?

    If you want to ACCESS the original directory after changed it, store it in a variable this way:

    SET ORIGINAL=%CD%
    

    and use %ORIGINAL% later, for example:

    dir /b *.tex > %original%\%2.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a simple batch file that would perform some Visual Studio
I want to create a batch file that moves all the files in this
i want to create a batch file that executes command in it every 1
I want to create a batch file which will parse through a given directory
I want to build .NET solution using batch file. I am aware that I
I want to know simply how to create a batch file from .exe file?
I'm new to Windows batch files, but I'm writing a .bat file that just
I want to create a batch file to run java project directly. I want
I created a really small batch file that I want to be able to
I want to create a batch file which only continues if MASTERRESET.DLL consists of

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.