1

Let me set the stage of my issue. I have a folder (FOLDER_ABC). Within that folder, there is a folder for my application, including a unique and always changing version number (application-v1.3.4). Within that folder, there is the application (application-v1.3.4.exe) - which will also change periodically.

C:\FOLDER_ABC\application-v1.3.4\application-v1.3.4.exe

In this section below I create a directory listing of the FOLDER_ABC for any folders starting with application* and store that folder name into a file called directory.txt. I then create a perameter and store that directory into it. I'm doing it this way, versus applying the direct full path to the directory or file, since the versions will change and I don't want to hard code the batch script.

cd C:\FOLDER_ABC\
dir  application* /b /ad>"C:\FOLDER_ABC\directory.txt"
set /p verdir= <C:\FOLDER_ABC\directory.txt

Here is my issue. In the section below, I'm trying to get my batch script to run the application*.exe file, and continue on with my batch file. It currently runs my application, but it hangs and doesn't continue the rest of my batch script. I'm really new to all this coding so I appreciate the help. I assume it could be something related to me not closing the FOR loop properly? How can I get it to continue on to :FINISH?

cd "C:\FOLDER_ABC\%verdir%\"
FOR /f "tokens=*" %%G IN ('dir /b *.exe') DO %%G;

:FINISH
ECHO THE END
exit

Figured it out, but didn't have enough StackOverflow credits to answer my own question. My solution is listed below. Thanks everyone. You pointed me in the right direction.

cd "C:\FOLDER_ABC\%verdir%\"
FOR %%G in (*.exe) DO START %%G

3 Answers 3

1

you can try:

FOR /f "delims=" %%G IN ('dir /b /a-d *.exe') DO start "" "%%~G"
Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure if this is your problem, but it is possible that the ; is causing problems. You do not terminate commands with ; in batch files.

There is no need for a temporary file. Your code can be greatly simplified with FOR:

pushd c:\folder_abc
for /d %%F in (application*) do cd "%%F"
for %%F in (*.exe) do "%%F"

:FINISH
ECHO THE END
exit /b

1 Comment

Thanks. Yeah, I figured out something similar that worked. I added it to the question above. Didn't have enough credits to answer my own question. Thanks! And the ";" was a typo. Sorry about that.
1

Try using the START command:

FOR /f "tokens=*" %%G IN ('dir /b *.exe') DO START %%G;

There may be other better ways if achieving what you want, for example, if you know that the exe always has the same name as its directory, and that there will be only one such directory, you could do the following:

FOR /D %%i in (application-v*) DO START %i\%i.exe

UPDATE

From comments:

My only issue, which I just realized, is that the application folder and application name are not always identical.

In that case, you could try something like:

for /d %%i in (application-v*) do for %%j in (%%i\*.exe) do start %%j

2 Comments

My only issue, which I just realized, is that the application folder and application name are not always identical. I want it to start any .exe within the app folder. C:\FOLDER_ABC\application-v1.3.4\Helloworld-v1.3.4.exe
I tried adding the app version to a parameter, just as I did with the folder, but I recieved the following error: 'C:\FOLDER_ABC\application-v1.3.4\application-v1.3.4.exe' is not recognized as an internal or external command, operable program or batch file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.