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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:39:38+00:00 2026-05-31T04:39:38+00:00

In Windows cmd batch, I try to call a batch file: call .\%%R\scenery\list bgl.bat

  • 0

In Windows cmd batch,
I try to call a batch file:

call ".\%%R\scenery\list bgl.bat" ".\%%R\scenery\"

In the “list bgl.bat” I have:

IF "%1"=="" ( dir *.bgl /b > list_bgl.txt ) ELSE  ( dir "%1*.bgl" /b > list_bgl.txt )

and it crashes somewhere in the place of condition. The if true part works OK (if I run the batch “list bgl.bat” directly). But If I run it from a batch file, so the else block fails and the script crashes. Do see where is problem?

Update:

T:\test\scenery>call ".\list bgl.bat"
T:\test\scenery>IF "" == "" (dir *.bgl /b   1>list_bgl.txt )  ELSE (dir "*.bgl" /b   1>list_bgl.txt )
T:\test\scenery>ECHO DONE
DONE

T:\test\scenery>pause
Press any key to continue

T:\test\scenery>call ".\list bgl.bat" ".\"
T:\test\scenery>IF ".\" == ""
(dir *.bgl /b   1>list_bgl.txt )  ELSE (dir ".\*.bgl" /b   1>list_bgl.txt )
T:\test\scenery>ECHO DONE
DONE

T:\test\scenery>pause
Press any key to continue
T:\test\scenery>

Well this works. Command parametr no. 1 was tested from cmd-line

EDIT2:
When I call the main batch (from parent directory) I see no error, but the file is not created in the specified directory but in the main directory from where the main run was performed:

:

@echo off
cls
for /F "tokens=*" %%R in ('dir * /A:D /b') do (
echo ".\%%R\scenery\list bgl.bat"
call ".\%%R\scenery\list bgl.bat" ".\%%R\scenery\"
)
pause

EDIT3:
Yeah, I have it. Problem here:

 > list_bgl.txt

I miss the path there… This works:

IF "%~1"=="" ( dir *.bgl /b > list_bgl.txt ) ELSE ( dir "%~1*.bgl" /b > "%~1list_bgl.txt" )
  • 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-31T04:39:39+00:00Added an answer on May 31, 2026 at 4:39 am

    You are already enclosing your parameter in quotes during the call, then you add a second set of quotes within “list bgl.bat”. That can cause problems. If you want to add enclosing quotes within “list bgl.bat” then you need to first remove any possible existing enclosing quotes using %~1.

    IF "%~1"=="" ( dir *.bgl /b > list_bgl.txt ) ELSE  ( dir "%~1*.bgl" /b > list_bgl.txt )
    

    update
    You have shown an example of what works, but we need to see what is not working. The quote / %~ issue was real, but it looks like you have something else that is causing problems. I’m curious what the run-time value of %%R is? I’m also surprised that the path to your called batch file can vary.

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

Sidebar

Related Questions

A windows batch file ( called.bat or called.cmd ) can be called from another
trying to run a simple batch file in windows 2008 task scheduler call cleanup.bat
I have a batch file run.bat that requires many arguments for it to run.
I have a batch file (in windows XP, with command extension activated) with the
Is it possible to filter list of arguments in windows batch file? Assuming it
I am using process.Start(); to start a batch file. The CMD windows appears fine
Possible Duplicate: Windows batch files: .bat vs .cmd? Hi, I am learning Windows Batch
I have a batch file that calls a Windows GUI application. The GUI app
How to hide cmd window while running a batch file? I use the following
I wanted to run a .cmd file from Java. I have something which works

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.