`Felix` Posted December 15, 2005 Share Posted December 15, 2005 Hi there,I would like a little bit of help putting together a smarter batch file that i can reuse...Currently i am basically doing this on my application CD'scd dir1\start /wait doIT.exe (do it my custom installer that i have put together for each of my applications to silently install and configure. i.e. add reg settings etc.)cd ..cd dir2\start /wait doIT.execd ..cd dir3\start /wait doIT.exeand so on...I thought it would be good/cleaner to do something likefor %%i in (dir) do if exist %%i\doIT.exethe code to run... I know the code above is not correct - but this will give you the idea of what i am seeking... i would appreciate any help/advice you can offer.... Link to comment Share on other sites More sharing options...
Yzöwl Posted December 15, 2005 Share Posted December 15, 2005 (edited) Try something like thisfor /f "delims=" %%? in ('dir/b/s/a-d "doIT.exe" ^2^>nul') do if errorlevel 0 start "" /w "%%~f?"orfor /r %%? in ('dir/b/a-d "doIT.exe" ^2^>nul') do if errorlevel 0 start "" /w "%%~f?" Edited December 15, 2005 by Yzöwl Link to comment Share on other sites More sharing options...
`Felix` Posted December 15, 2005 Author Share Posted December 15, 2005 Try something like thisfor /f "delims=" %%? in ('dir/b/s/a-d "doIT.exe" ^2^>nul') do if errorlevel 0 start "" /w "%%~f?"orfor /r %%? in ('dir/b/s/a-d "doIT.exe" ^2^>nul') do if errorlevel 0 start "" /w "%%~f?"No joy but thankyou for your suggestions... Link to comment Share on other sites More sharing options...
nakira Posted December 15, 2005 Share Posted December 15, 2005 Try thisfor /d %%a in (*) do if exist %%a\Doit.exe start /wait %%a\doit.exe Link to comment Share on other sites More sharing options...
Yzöwl Posted December 15, 2005 Share Posted December 15, 2005 (edited) in each of the examples I gave, you would of course need to be at least in the root of the CDe.g.@echo off&setlocal enableextensionsfor /f "usebackq skip=1" %%? in (`wmic cdrom where "MediaLoaded='TRUE'" get drive ^2^>nul`) do if errorlevel 0 set CDROM=%%?if not defined CDROM endlocal&goto :eofpushd %CDROM%for /f "delims=" %%? in ('dir/b/s/a-d "doIT.exe" ^2^>nul') do if errorlevel 0 call :RunIt "%%~f?"popd&endlocal&goto :eof:RunItstart "" /w %1goto :eofanother method toofor /f "delims=" %%? in ('dir/b/ad') do ( if exist "%%?\doIT.exe" ( pushd %%? start "" /w doIT.exe popd ) ) Edited December 15, 2005 by Yzöwl Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now