0

how can batch read file names and run them in loop.

I would have a file with file names and run them within a batch.

File names would be.

user1
user2
user3

And their location would be

C:\User\Desktop\user1.exe
C:\User\Desktop\user2.exe
C:\User\Desktop\user3.exe

If all can be done without input file that would be even better.

edinvnode
  • 3,497
  • 7
  • 30
  • 53

1 Answers1

1

The code to use without a list file is:

for %%I in ("%USERPROFILE%\Desktop\*.exe") do "%%~fI"

The code to use with a list file is:

for /F "usebackq delims=" %%I in ("File with the file names.txt") do "%USERPROFILE%\Desktop\%%I.exe"

The path can be whatever is wanted. Here is specified the desktop folder of the current user.

For understanding the used command FOR and how it works, open a command prompt window, execute there the following commands and read entirely all help pages displayed for the command very carefully.

  • for /?

You might be also interested in this answer explaining the 4 methods to start or call an application.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143