Reputation: 53
I've been looking for the correct code for my batch file to start a program and open a file by extension only. I've been searching and all I can find is opening a file by filename only, without extension. I would like to do it the other way around. I've tried multiple
start "C:\program files\folder\program name.exe" d:\folder\filename.extension
I've found some answers for other programs and tried them but they didn't work. I've tried to replace filename by * but it didn't work as well.
The reason I'm asking is becasue the filename will change every buildnumber but the extension is unique in that folder. Hope you can help me out. Thanks
Upvotes: 1
Views: 2044
Reputation: 6557
You can do as follows
rem ** go to the folder
CD d:\folder
rem ** find all the filenames with required extension using a for-loop
FOR /F "tokens=1 delims=" %%A in ('DIR /b *.extension') do (
rem ** Added some delay before start as per OP comments
timeout 5
rem ** use start command
start "C:\program files\folder\program name.exe" %%A
)
Edit : Added Timeout for some delay before start as per OP's comment
Upvotes: 1
Reputation: 208077
You should be able to do:
start "" filename.extension
The double double quotes provide the name for the window for some weird, illogical, Microsoft-y reason.
Upvotes: 2