Link to home
Start Free TrialLog in
Avatar of fever_rca
fever_rcaFlag for United States of America

asked on

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

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.
Avatar of AlexFM
AlexFM

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

dir sdat* /B >> tmp.bat
call tmp.bat
Avatar of fever_rca

ASKER

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?

Thanks,
Richard
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
d:
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!  

Richard
You can do the same replacing >> with > (overwrite).