Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Running *.bat in a batch file  (Read 2031 times)

0 Members and 1 Guest are viewing this topic.

akpolarsmurf

  • Guest
Running *.bat in a batch file
« on: September 15, 2006, 12:36:34 PM »
Hi everyone,

I'm trying to write a batch file that will be called with the scheduled tasks function of Windows XP.  In this batch file, I want to be able to run any batch file found in a certain directory.  For example:

call e:\test\*.bat

but for some reason I can't get this to work.  Is there a method of executing multiple batch files without knowing what the names of those files will be?

Dusty



    Egghead

  • I could if she would, but she won't so I don't.
  • Thanked: 75
  • Experience: Beginner
  • OS: Windows XP
Re: Running *.bat in a batch file
« Reply #1 on: September 15, 2006, 02:48:21 PM »
I cannot find any info on using a wildcard with Call.  Have found one site which indicates that the filename is definitely required.

Here is the C.H. Call site - note that the filename is not bracketed indicating that it is mandatory.

Good luck
One good deed is worth more than a year of good intentions.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Running *.bat in a batch file
« Reply #2 on: September 15, 2006, 03:55:39 PM »
You can't use a wildcard in a call, the cmd processor is just not that sophisticated. You can however create a loop to do a call over the collection of batch files:

Code: [Select]
@echo off      
for /f "tokens=* delims=" %%i in ('dir /b e:\test\*.bat') do call "%%i"

This batch file needs to be in same directory as your batch files. If not, you may need to use the /s switch. You also have some limited options for sorting the files. Check out dir /? for details.

 8-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

akpolarsmurf

  • Guest
Re: Running *.bat in a batch file
« Reply #3 on: September 15, 2006, 05:30:19 PM »
Excellent!  I was even able to put in a provision that after each bat file was run, it would be renamed to .BAK so it would not be run again.  Thanks for the help!

soSagtDieHex

  • Guest
Re: Running *.bat in a batch file
« Reply #4 on: September 16, 2006, 08:19:30 PM »
Quote
I was even able to put in a provision that after each bat file was run, it would be renamed to .BAK so it would not be run again.

but as the FOR cycle steps through all the .bat files in e:\test there should be no risk of running any of them again, if I understand how FOR works.

How did you manage to rename *.bat to *.bak anyway ?
I mean, how/where can you do it ?
After the
do call "%%i"
it shouldn't work.