Solved Batch file that will run exe file in a set of directorie

May 21, 2019 at 08:50:48
Specs: Windows 10
An existing batch file runs an executable located under C:\Program Files (x86)\Software\App\version1

How do I future proof this batch file so that it continues to run the executable when the software gets upgraded version2, version3, etc.?

With every new revision of the software, a new "Version" folder is created, and as a result the executable gets moved to the new version folder.


See More: Batch file that will run exe file in a set of directorie

Reply ↓  Report •

#1
May 21, 2019 at 09:56:18
@echo off
cd "full\path\of\dir1"
start "C:\Program Files (x86)\Software\App\version1\file.exe"
cd "full\path\of\dir2"
start "C:\Program Files (x86)\Software\App\version1\file.exe"
cd "C:\full\path\of\dir3"
start "C:\Program Files (x86)\Software\App\version1\file.exe"
cd "C:\full\path\of\dir4"
start "C:\Program Files (x86)\Software\App\version1\file.exe"


check if the .exe is running by opening the task manager and looking for the .exe filename

"With every new revision of the software, a new "Version" directory is created, and as a result the executable gets moved to the new version dir.ectory"

is there any patern in which the new folder is called when switching versions?
is there a version.txt file (some programs do this to keep track themselfes)?

i5-6600K[delid]@4.9GHz/4.4GHz cache@1.504v | 2x4GB Crucial-DDR4-2400CL17@CL12-15-15-28 1T 3000MHz@1.45v | Sapphire Nitro+ SE RX 590 8GB@1450Mhz core@0.925v/2250MHz@1500MHz timings BiosModded


Reply ↓  Report •

#2
May 21, 2019 at 21:22:57
✔ Best Answer
I would guess that the executable retains the same name, or at least the first part of it. If the "version" directories are all rooted in one base, then maybe you could just do a "dir /s /b xxx*.exe" and take the full path of the latest one. Easier said than done, however, since once you've got the list, you need to get the latest date, and usually the year is last, so "12/01/2018" will sort wrongly to "01/01/2019". Easy enough to manipulate with batch, using tokens:
@echo off & setlocal
set prev=1
:aa
for /f "tokens=*" %%a in ('dir /b /s xxx*.exe') do call :xx %%~ta %%a
echo timestamp: %prev%
echo target: %targ%
goto :eof

:xx
for /f "tokens=1-3 delims=/" %%k in ("%1") do (
echo %%m-%%k-%%l %4
if %%m-%%k-%%l leq %prev% goto :eof
set prev=%%m-%%k-%%l
set targ=%4
)
exit /b

I'll wait to see if you need further assistance and pending any further feedback from you.

message edited by nbrane


Reply ↓  Report •
Related Solutions


Ask Question