ShizukaSM
ShizukaSM

Reputation: 333

How to execute any .exe by using a batch file?

I know that I can start an exe by doing:

start "" /b filename.exe

But that requires me to know the name of filename.exe, how could I do that for any general file ending with .exe? I tried the obvious wildcard implementation:

start "" /b *.exe

Windows, however, gives me an error saying it cannot find "*.exe" file.

Upvotes: 4

Views: 18911

Answers (5)

Vassilis Barzokas
Vassilis Barzokas

Reputation: 3232

From cmd run this to the folder that has all the exe you wish to run:

for %x in (*.exe) do ( start "" /b  "%x" )

Upvotes: 4

Batcher
Batcher

Reputation: 167

Don't blame their codes for space issue. You should know how to use double quotation marks.

for /f "delims=" %%a in ('dir /b /s *.exe') do (
    start "" "%%a"
)

Upvotes: 0

Guido Preite
Guido Preite

Reputation: 15128

if you plan to run inside a batch file you can do in this way:

for %%i in (*.exe) do start "" /b "%%i"

if you want to skip a particular file to be executed:

for %%i in (*.exe) do if not "%%~nxi" == "blabla.exe" start "" /b "%%i"

if is necessary to check also the subfolders add the /r parameter:

for /r %%i in (*.exe) do start "" /b "%%i"

Upvotes: 13

Michael
Michael

Reputation: 148

In a bat file add this line

FOR /F "tokens=4" %%G IN ('dir /A-D /-C ^| find ".exe"') DO start "" /b %%G

This execute every .exe file in your current directory. same as

*.exe

would have done if * were supported on batch.

If you want to execute it directly from a command line window, just do

FOR /F "tokens=4" %G IN ('dir /A-D /-C ^| find ".exe"') DO start "" /b %G

Upvotes: 0

Sheng
Sheng

Reputation: 3555

Hoep it helps

for /f "delims=" %%a in ('dir /b /s "*.exe"') do (
    start %%a
)

You should first use dir command to find all exe files, and then execute it.

Upvotes: 2

Related Questions