We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


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

fever_rca asked
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.
Watch Question

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

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


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?

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


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!  


You can do the same replacing >> with > (overwrite).
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.