0

I have a project which builds an application and whenever it builds the application the names it generates are like this MyApp1.1.exe, myapp1.2.exe, myApp,1.3.exe etc. I would like to deploy the application in another environment whenever there is a new build. But the problem is that I'm using the following in command in the batch script, which is is keep throwing me an error

MyApp1.*.exe

But it always throws an error in the command line saying that 'MyApp1.*.exe' is not recognized as internal or external command, operable program or batch file. I know that this should be very simple but I could not seem to find any solution

  • At the same time as you create the `MyApp.a.b.exe`, also create a `MyApp.latest.bat` that just runs this newly created version. – Ken Y-N May 11 '21 at 04:30
  • 2
    You cannot use the * wildcard operator to select a single file. You will need to use batch scripting and a for loop, similar to this (https://stackoverflow.com/questions/1100452/get-filename-in-batch-for-loop/1100466). – Will Walsh May 11 '21 at 04:30
  • 3
    no, you can't do that. in `cmd` do `for %i in (MyApp*.exe) do start "" "%~i"`. double up on the `%` when used from batch-file. – Gerhard May 11 '21 at 05:05
  • What documentation did you find in a book or online that says you can use that syntax in a batch file? Would like to know for my own documentation purposes. – Squashman May 11 '21 at 11:34
  • @Gerhard Thank you. It actually worked :) – Peter Jackson May 17 '21 at 05:03

1 Answers1

0

cmd, which is used to run batch-files, requires that you run for loops to do something for each item. You therefore need to give for some criteria and it will return the list based on that. You can then do something with these metavariables.

@echo off
for %%i in (MyApp*.*.exe) do echo start "" "%%~i"

For the purpose of this demonstration, I am not actually running the executable's, instead I just echo the full command. If you feel that it is suitable for this purpose, then simpy remove echo from the echo start "".. section.

Gerhard
  • 22,678
  • 7
  • 27
  • 43