Extend script to find 2 more files and execute all

Can somebody help me to change the underneath CMD script from oBdA to find 3 programs and run 2nd  command when the first is finished and the 3rd when the 2nd is finished (a 10 second delay between commands is also good)

Thanks Danny
_____________________________________________
@echo off
setlocal enabledelayedexpansion
if "%~1"=="" (
      set /p FileName=Give the filename:
      if "!FileName!"=="" goto :eof
) else (
      set FileName=%~1
)
call :Where Folder "%FileName%"
if "%Folder%"=="" (
      echo %FileName% not found.
      exit /b 1
)
echo Folder: %Folder%

REM ========== Only function after this line! ==========
goto :eof
:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa&goto :eof)
set %~1=
goto :eof
LVL 6
Danny KonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The script only searches for the program you supplied, and displays the folder it is in. It does not execute anything.
To modify it to search and execute N programs, I recommend to use following script. But now you will have to provide all programs to execute in the commandline, like with (calling the script SearchAndExec.cmd):
searchAndExec Prog1.exe Prog2.exe Prog3.exe

Open in new window

@echo off
setlocal enabledelayedexpansion
if "%~1"=="" echo Please supply executable names with the command& pause & exit /b 1

for %%F in (%*) do (
  call :Where FullPath "%%~F"
  if [%FullPath%]==[] (
      echo %%F not found.
      exit /b 1
  )
  call %FullPath%
)
exit /b

REM ========== Only function after this line! ==========

:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa& exit /b)
set %~1=
exit /b 1

Open in new window

Danny KonAuthor Commented:
Qlemo,

You are right but i changed the script from oDbA where it says
echo Folder: %Folder%
to
"%Folder%%FileName%" and then it will execute the program
It would be much appriciated if it will work in the same way so it will first ask for the 3 programs and then excecute 1, wait execute 2 wait and execute 3

Thanks

Danny
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Very inconvenient to get asked for 3 programs! Why would you like to do that? One single typo, and it does not work at all.
I would recommend to allow for a single prompt asking for all programs to execute.

Further, do you want to have all programs checked first, so executing only starts if all have been found?
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Danny KonAuthor Commented:
Qlemo
 
It doesnt has to do ask for the program but is it possible that i can change this in the batch
as an example i want to find the file sqldump.exe
sometimes it will be in C:\Program Files\MySQL\MySQL Server 5.7\bin
but on other SQL version or in a other computer it will be in a different directory  

something like:
___________
@echo off
setlocal enabledelayedexpansion
if "%~1"=="" (
Program 1
Program 2
program 3
      if "!FileName!"=="" goto :eof
) else (
      set FileName=%~1
)
call :Where Folder "%FileName%"
if "%Folder%"=="" (
      echo %FileName% not found.
      exit /b 1
)
execute 1
wait
execute 2
wait
%mysqldump% -u root -ppassword databasename > %databasename%

REM ========== Only function after this line! ==========
goto :eof
:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa&goto :eof)
set %~1=
goto :eof
__________
Thanks Danny
Danny KonAuthor Commented:
Qlemo,

I overlooked your last comment yes it has to say something like "this script will not work" if i doesnt find all the programs

Danny
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
This allows for an arbitrary count of progs to be provided in the first FOR. Only if all of them are found execution starts in sequence as given.
@echo off
setlocal enabledelayedexpansion

for %%F in (Prog1.exe Prog2.exe Prog3.exe) do (
  call :Where FullPath "%%~F"
  if [!FullPath!]==[] (
      echo %%F not found -- Abort
      exit /b 1
  )
  set FullPaths=!FullPaths! "!FullPath!"
)
for %%F in (%FullPaths%) call %%F
exit /b

REM ========== Only function after this line! ==========

:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa& exit /b 0)
set %~1=
exit /b 1

Open in new window

Danny KonAuthor Commented:
Qlemo,

I dont understand how i can use this in my question  
As you see in my example i need to give additional parameters to the programs, how i can do this in your solution?

for %%F in (Prog1.exe Prog2.exe mysqldump.exe)

Where i can put underneath ?

Prog 1
wait
Prog 2
wait
%mysqldump% -u root -ppassword databasename > databasename

Thanks for your help

Danny
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That is more complex, and you should have told from start. It now results in a more cumbersome script:
@echo off
setlocal enabledelayedexpansion

call :Where FullPath1 Prog1.exe && ^
call :Where FullPath2 Prog2.exe && ^
call :Where FullPath3 mysqldump.exe && (
  !FullPath1!
  !FullPath2!
  !FullPath3! -u root -ppassword databasename > databasename
  exit /b 0
)
echo *** ABORT ***
exit /b 1


REM ========== Only function after this line! ==========

:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa& exit /b 0)
echo '*** %~2 not found anyhwere'
set %~1=
exit /b 1

Open in new window

Feel free to name FullPath1 etc. different and more specific. Those names are arbitrary.
Danny KonAuthor Commented:
Qlemo,

You are right i had to be more clear in the question.
I used wordpad.exe mspaint.exe and calc.exe for testing the script,  it doesnt work as expected wordpad is not finding the file

Danny

-----test file--------
@echo off
setlocal enabledelayedexpansion

call :Where FullPath1 wordpad.exe && ^
call :Where FullPath2 mspaint.exe && ^
call :Where FullPath3 calc.exe && (
 
!FullPath1!wordpad.exe "C:\Users\POS\Desktop\FILE.TXT"
!FullPath2!mspaint.exe
!FullPath3!calc.exe
 
exit /b 0
)
echo *** ABORT ***
exit /b 1


REM ========== Only function after this line! ==========

:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa& exit /b 0)
echo '*** %~2 not found anyhwere'
set %~1=
exit /b 1
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
No, you do NOT repeat the application names in the actual call. You need those only in the :Where check.
@echo off
setlocal enabledelayedexpansion

call :Where FullPath1 wordpad.exe && ^
call :Where FullPath2 mspaint.exe && ^
call :Where FullPath3 calc.exe && (
  !FullPath1! "C:\Users\POS\Desktop\FILE.TXT"
  !FullPath2!
  !FullPath3!
  exit /b 0
)
echo *** ABORT ***
exit /b 1


REM ========== Only function after this line! ==========

:Where <Variable> <File>
set %~1=%~dp$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~dpa& exit /b 0)
echo '*** %~2 not found anyhwere'
set %~1=
exit /b 1

Open in new window

Danny KonAuthor Commented:
Qlemo

Then i only get the path
'C:\Program Files\Windows NT\Accessories\' is not recognized as an internal or external command,

Danny
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Sorry, my fault. Forgot to adapt that.
@echo off
setlocal enabledelayedexpansion

call :Where FullPath1 wordpad.exe && ^
call :Where FullPath2 mspaint.exe && ^
call :Where FullPath3 calc.exe && (
  !FullPath1! "C:\Users\POS\Desktop\FILE.TXT"
  !FullPath2!
  !FullPath3!
  exit /b 0
)
echo *** ABORT ***
exit /b 1


REM ========== Only function after this line! ==========

:Where <Variable> <File>
set %~1=%~F$PATH:2
if not "!%~1!"=="" goto :eof
echo '%~2' not found in path; searching C: ...
for /f "delims=" %%a in ('dir /a:-d /s /b "C:\%~2"') do (set %~1=%%~Fa& exit /b 0)
echo '*** %~2 not found anyhwere'
set %~1=
exit /b 1

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Danny KonAuthor Commented:
Qlemo

Sorry that this give you so much trouble,
It start wordpad but it does not find the file 100% sure that the file is there very strange

Danny
Danny KonAuthor Commented:
Qlemo

I think i found the problem, if i put the
 !FullPath1!
  !FullPath2!
  !FullPath3!

like this it will start also the file
 
 "!FullPath1!"
  "!FullPath2!"
  "!FullPath3!"

Thanks so much for your help

Danny
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.