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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:53:08+00:00 2026-06-10T19:53:08+00:00

I have 2 batch files. The first one needs an input argument which is

  • 0

I have 2 batch files.

The first one needs an input argument which is a path of a parent folder. It reads the names of all subfolders inside the parent folder and executes the second batch file for each subfolder.

BATCH FILE 1

@echo off
for  /d %%Y in (%1/*) do (  
set SubfolderNameAndPath=%%Y
call batch2.bat %SubfolderNameAndPath% 
)

The second batch file uses as input argument the SubfolderNameAndPath and executes an Evaluate.exe for all the files that exist in each subfolder. It saves the results of the Evaluate.exe to a text file “results” with an extension that carries the name of the subfolder that each time has been accessed. (results_%~n1.txt).

BATCH FILE 2

@echo off
for  %%X in (%1/*) do (  
echo Evaluate.exe  %%X AnotherArgumentHere -o results_%~n1.txt   
)

When I run the batch1 (batch1.bat ParentFolderPath) even if it seems to call the batch2.bat, the batch2.bat is not executed. I believe that something goes wrong with the way that I define the input arguments for the batch2.bat but I cannot figure out what it is.

The %SubfolderNameAndPath% does not contain any spaces. Neither the path to the folder does.
I would really appreciate your help on that.

  • 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-10T19:53:09+00:00Added an answer on June 10, 2026 at 7:53 pm

    Well, first, when inside a bracketed pair you can’t set a variable then access it with the %’s. You must first (before the for loop) setlocal enabledelayedexpansion, then access your variables with the !‘s rather than the %‘s.

    But since you do not do anything with %SubfolderNameAndPath% anyway, you should just eliminate it.

    Second, you need to compensate for paths containing spaces, so hopefully my code below will work out for you. To do this, batch uses a special notation for arguments passed to to remove double quotes around them. So, if %1 = "This string", then %~1 = This string. Also, if %1 = This string, then %~1 still = This string. So there is no drawback to using the %~1 notation, unless you want to retain any double quotes.

    So, int batch1.bat, we remove any potential quotes surrounding %1, and then place double-quotes around %~1/*, and also double-quote %%Y just in case there are spaces in it.

    batch1.bat

    @echo off
    for  /d %%Y in ("%~1/*") do call batch2.bat "%%~Y"
    

    Then we do the same thing for batch2.bat, but more of it.

    batch2.bat

    @echo off
    for  %%X in ("%~1/*") do (
      echo Evaluate.exe  "%%~X" AnotherArgumentHere -o "results_%~n1.txt"
    )
    

    EDIT: 2012/09/05 15:21

    How’s this grab you? Instead of calling a seprate batch:

    for /d %%x in (%1\*) do (
      for /f "tokens=*" %%y in ( 'dir /b /a:-d "%%~dpnxx"' ) do (
        echo Evaluate.exe %%~nxy AnotherArgumentHere -o "results_%%~nxx.txt" 
      )
    )
    

    (The above can be put all on one line, just remove the brackets.)

    I’m assuming the output is:
    Evaluate.exe <file_name> AnotherArgumentHere -o "results_<directory_name>.txt"

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

Sidebar

Related Questions

I have made a batch file that call another one program.bat , the first
I have several batch files that I call from a parent batch file. I
I have two batch files which is used to run a large C++ build,
I have a Windows batch file that processes all the files in a given
I'm writing a simple batch downloader for files, which have the format Y-m-d.pdf. I
I have two files lets say a.xls and b.xls . The first one contains
I have a batch file which calls a Perl file which requires a input
I have a for loop in a batch file: @echo off set logpath1=C:\path\to\first\log set
I have a script located at /tmp/My Batch Script Files/Processing How would I run
I have a batch file that requires the user to enter a file path.

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.