Kiera Smith, this question is similar to this one posted also by you.
Your posted code has some mistakes and unused code making it really hard to answer it. However, I try it nevertheless.
First, everything between round brackets is a block. cmd.exe
parses an entire block and expands all variable references within percent signs already on parsing the block. Therefore %pathexe%
in second for loop is expanded already before defined at all, i.e. replaced by an empty string.
Second, environment variable arch
is not used anywhere although there is an extra if condition to define it.
It is unclear if the block within most outer (
and )
should be the block for the if condition. This is currently not the case as the if condition is just for set arch=x64
. Opening (
of an if block must be on same line as keyword if after the condition and set arch=x64
would be moved into the block and not outside.
Version of Windows assigned to variable ver
is not further processed at all.
/r
on second for loop results in searching recursive for *.exe
in specified folder and all subfolders. Is that really wanted?
Do you have ever run your batch file from within a command prompt window and have used in first line echo on
instead of echo off
?
This would make it possible to debug what command line interpreter really interprets on executing the batch file.
Edit after a providing a more complete code:
It looks like your entire code could be reduced to following lines:
@echo off
cls
echo.
setlocal DisableDelayedExpansion
if "%ProgramFiles(x86)%"=="" (set "arch=\86") else (set "arch=")
set "pathexe=%~dp0files%arch%\exe"
for %%I in ("%pathexe%\*.exe") do start "Running %%~nI" /wait "%%I"
endlocal
Or even more reduced:
@echo off
cls
echo.
if "%ProgramFiles(x86)%"=="" (set "arch=\86") else (set "arch=")
set "pathexe=%~dp0files%arch%\exe"
for %%I in ("%pathexe%\*.exe") do start "Running %%~nI" /wait "%%I"
The environment variable arch
is either initialized with the string \86
or removed if existing at all depending on existence of environment variable ProgramFiles(x86) which exists only on Windows x64.
The processor architecture does not matter for installing x86 or x64 executables. It matters which version of Windows is processing the batch file. It is possible to use on a computer with x64 processor nevertheless Windows x86 if more then 4 GB is not installed and x86 drivers are available also for the hardware components of the computer. See also Why %processor_architecture% always returns x86 instead of AMD64?
The path to the EXE files is:
- path of the batch files referenced with
%~dp0
and ending always with a backslash,
- plus fixed directory name
files
,
- plus string
\86
on Windows x86 (backslash as directory separator + directory name 86
) or nothing on Windows x64,
- plus a backslash as directory separator and directory name
exe
.
Then each .exe
file in this directory is started with command start and batch file processing is halted always until each started application terminated itself.