Reputation: 11
I want to create a .bat file that will help me to find/search a particular .exe file in folders in a particular location and then run that .exe file.
e.g
below two are not able to find and run the file.
1st program
pushd G:\data-a\test
FOR /F "delims=" %F IN ('dir /S /b autorun.exe') DO SET ExePath="%F"
%ExePath%e
2nd program
for /r G:\data-a\test %a in (autorun.exe) do "%a"
from the above two different program I put it in to notepad for creating two different .bat file and executed one after anther file. but that was unable to locate and run autorun.exe file.
just for example my autorun.exe file exact locations are
G:\data-a\test\test1\t1 and G:\data-a\test\test1\t1
but in G:\data-a\test location there may be several subfolders.
so to run autorun.exe one by one that to find the file in subfolder is difficult. I want to give the path G:\data-a\test in program and all the files will be found in subfolder and then run automatically.
Upvotes: 0
Views: 6971
Reputation: 263
or the one liner from the command prompt:
for /r g:\data %a in (filename.exe) do "%a"
used the quotes for %a in case the calling directory path has spaces in it
Upvotes: 1
Reputation: 1085
Three liner (use %%F if wrapping inside a batch file).
pushd G:\data
FOR /F "delims=" %F IN ('dir /S /b something.exe') DO SET ExePath="%F"
%ExePath%
Upvotes: 2