Computer Hope

Microsoft => Microsoft DOS => Topic started by: Blisk on April 25, 2014, 03:23:56 AM

Title: batch for run all bat files
Post by: Blisk on April 25, 2014, 03:23:56 AM
I have to try to run all batch files under folder subfolder wih one batch
I tried this bot not working
for /d /r %%i in (D:\myfloder\Drivers\conf\) do if exist "%%i\copylog.bat" start /wait call "%%i\copylog.bat"

bat file which must be runed is under D:\myfloder\Drivers\conf\MIKE\archive\bat

I tried to run batch files from other topic
Title: Re: batch for run all bat files
Post by: foxidrive on April 25, 2014, 03:47:15 AM
This will launch each batch file in that folder:

Code: [Select]
@echo off
cd /d "D:\myfloder\Drivers\conf"
for %%a in (*.bat) do call "%%a"
pause
Title: Re: batch for run all bat files
Post by: Lemonilla on April 25, 2014, 07:42:14 AM
Just make sure foxidrive's file isn't in D:\myflder\Drivers\conf or you will enter an infinite loop. Here is a workaround.

Code: [Select]
@echo off
cd /d "D:\myfloder\Drivers\conf"
for /f "delims=" %%A in ('dir /b *.bat ^| find /v "%~nx0"') do echo call "%%A"
echo.
echo All done.
pause

Proof of concept:
Code: (code) [Select]
@echo off

echo Before:
echo %time%
for %%a in (*.bat) do echo call "%%a"
echo %time%
echo.

echo After:
echo %time%
for /f "delims=" %%A in ('dir /b *.bat ^| find /v "%~nx0"') do echo call "%%A"
echo %time%
echo.

echo All done.
pause>nul
Code: (output) [Select]
T:\>findAllBat
Before:
 9:43:12.28
call "colorsd.bat"
call "colorText.bat"
call "countLines.bat"
call "findAllBat.bat"
call "note.bat"
call "realtime.bat"
call "snakeV1.bat"
call "spaces.bat"
call "test.bat"
 9:43:12.29

After:
 9:43:12.30
call "colorsd.bat"
call "colorText.bat"
call "countLines.bat"
call "note.bat"
call "realtime.bat"
call "snakeV1.bat"
call "spaces.bat"
call "test.bat"
 9:43:12.37

All done.
Title: Re: batch for run all bat files
Post by: Blisk on April 25, 2014, 01:07:15 PM
lemonilla thanks but not working.
file not found
Title: Re: batch for run all bat files
Post by: Blisk on April 25, 2014, 01:10:44 PM
This will launch each batch file in that folder:

Code: [Select]
@echo off
cd /d "D:\myfloder\Drivers\conf"
for %%a in (*.bat) do call "%%a"
pause

here nothing happends
Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 01:26:26 PM
Are your batch files in this folder: D:\myfloder\Drivers\conf
Title: Re: batch for run all bat files
Post by: Blisk on April 25, 2014, 01:36:28 PM
Are your batch files in this folder: D:\myfloder\Drivers\conf

no there must be batch which runs all batch files

batch files are under
 D:\myfloder\Drivers\conf\MIKE\archive\bat

but all folders are diferend because are from differend usernames, this one is for MIKE.
and there is 30 users and 30 folders which have 30 batch files which needs to be runned
Title: Re: batch for run all bat files
Post by: patio on April 25, 2014, 01:38:40 PM
 :P
Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 01:43:00 PM
no there must be batch which runs all batch files

batch files are under
 D:\myfloder\Drivers\conf\MIKE\archive\bat

but all folders are diferend because are from differend usernames, this one is for MIKE.
and there is 30 users and 30 folders which have 30 batch files which needs to be runned
Then you got your first code example completely backwards as your code is looking for all the batch files in that folder.
D:\myfloder\Drivers\conf\)
Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 01:51:27 PM
Hmm,
If there are 30 users how are we doing to know which one is logged in for the correct directory path?
Title: Re: batch for run all bat files
Post by: Blisk on April 25, 2014, 01:54:22 PM
Hmm,
If there are 30 users how are we doing to know which one is logged in for the correct directory path?

this is runned on server

and I need to run this batch files
Code: [Select]
@echo off
pushd "..\logfiles"
for /f "delims=" %%a in ('dir /b /od /a-d ') do set "lastest_file=%%a"
copy "%lastest_file%" "..\test\new"
popd
Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 01:56:30 PM
"Runned is not a word."
Does your browser not have spell check.

Nor does your reply answer my question.
Title: Re: batch for run all bat files
Post by: Blisk on April 25, 2014, 02:02:30 PM
"Runned is not a word."
Does your browser not have spell check.

Nor does your reply answer my question.

Don't know what you mean with user logged on?
Because it is not relevant for this batch files.

We need to search copy.bat files in subfolders
 D:\myfloder\Drivers\conf

and after that script will find copy.bat under

 D:\myfloder\Drivers\conf\MIKE\archive\bat
 D:\myfloder\Drivers\conf\JOE\archive\bat
 D:\myfloder\Drivers\conf\NIKE\archive\bat

and it will run that copy.bat files
Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 02:09:59 PM
So you said 30 folders with 30 batch files.  That is 900 batch files.  You really want to execute 900 batch files?
Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 02:13:54 PM
I have no idea what you are trying to accomplish.  But this is my take on it.
Code: [Select]
for /d %%G in (D:\myfloder\Drivers\conf\*) do (
FOR %%H in ("%%G\archive\bat\*.bat") do call "%%H"
)
Title: Re: batch for run all bat files
Post by: Salmon Trout on April 25, 2014, 02:24:19 PM
Quote
You really want to execute 900 batch files?

Remember that guy who had a 15,000 line batch a few months ago? Or was it 1500?

Title: Re: batch for run all bat files
Post by: Squashman on April 25, 2014, 03:32:50 PM
Remember that guy who had a 15,000 line batch a few months ago? Or was it 1500?
yeah, because his code was redundant and he didn't bother to use a loop.
Title: Re: batch for run all bat files
Post by: foxidrive on April 25, 2014, 10:18:26 PM
It helps when you get accurate/full information.  +1 to Patio.