Execute a file with a wildcard name in a DOS batch file?

Posted on 2006-03-21
Medium Priority
Last Modified: 2008-01-09
Hope I phrased that question correctly...  I have a file I execute weekly to update several computers.  The file name is always "sdatxxx.exe", where the xxxx is a number.  The number may be more than 4 digits in the future.

I would like to make a batch file I can execute to save several steps.  I can make all the commands, except for the file name.  How can I specify the file name using wildcards?  I tried "sdat****.exe", and that didn't cut it.  That's about the extent of my batch wildcard knowledge!  :-)

So can I use a batch file to execute a file, when the file name changes regularly?  If it makes a difference, I will be executing this file off a CD, and the file will be the only file on the CD.
Question by:fever_rca
  • 3
  • 2
LVL 48

Expert Comment

ID: 16255012
Assuming that there is only one file meeting the sdat* wildcard, this will work:

dir sdat* /B >> tmp.bat
call tmp.bat

Author Comment

ID: 16255490
I didn't explain enough, AlexFM.  I'm trying to execute the file from a CD, which is the D: drive.  With your bat file, it doesn't find the file because it's looking for the file on the C: drive.  The bat file will have to reside on the C: drive of the computers getting updated.

Is there a way to execute the sdat file when it's on the D: drive and the bat file is on the C: drive?

LVL 48

Accepted Solution

AlexFM earned 2000 total points
ID: 16255926
This is just an idea, you can make change according to your needs, for example:

dir D:\sdat* /B >> tmp.bat
CD \
call tmp.bat

Author Comment

ID: 16256202
Cool, I worked it out pretty much like what you suggested.  Here's what worked for me:

del c:\tmp.bat
dir d:\sdat* /B >> C:\tmp.bat
call c:\tmp.bat

I had to put the delete command first.  That's for the next time the batch file is ran, because there's all ready a "tmp.bat" file with a sdat****.exe listed in it.  Otherwise the multiple sdat listing causes the command to endlessly list the file name down the screen.

Thanks for your prompt results!  

LVL 48

Expert Comment

ID: 16256225
You can do the same replacing >> with > (overwrite).

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question