|
Answer» I have fev batch files in differend folders and it works as they should when I run it manually. But I like to create batch to find and start those batch files where they are. I tried this script but problem is because it finds batch files and it EXECUTE in the same folder as this script, but that is wrong. Batch which are find must be executed where they are. Can someone help me with this please?
Code: [Select]for /f "delims=|" %%a in ('dir /B /S new_sendmail1.bat') do call "%%a"I forget to write that batch files which must be executedn by this master batch have relative paths, because of idfferend names of some folders where they are stored, but LAST folder where they are stored is the same for all batch files, like this. I didn't use full paths because folders like that are all together AROUND 100. d:\users\george\files\logs\new_sendmail1.bat d:\users\mike\files\logs\new_sendmail1.bat d:\users\joe\files\logs\new_sendmail1.batThe CD command and the %cd% variables are useful things to know about. In the FOR command you can use the CD command to make each folder where a batch was found, in turn, the current directory, and thus execute from there. You can get the batch path by using the standard FOR variable modifers ~d and ~p.
Here is the master.bat file that runs the individual user batch scripts I PUT it in d:\users
echo off echo Starting master.bat Echo I am master.bat echo I am stored in: %~dp0 echo I am running from: %cd% echo Running individual user batches... set thisfolder=%cd% for /f "delims=|" %%a in ('dir /B /S new_sendmail1.bat') do cd "%%~dpa" & call "%%a" cd "%thisfolder%" echo Back in master.bat echo Back in folder: %cd% echo Ended master.bat pause
This is my dummy new_sendmail1.bat file identical copies stored in d:\users\george, d:\users\mike, and d:\users\joe
echo off echo This is new_sendmail1.bat echo I am stored in: %~dp0 echo I am running from: %cd% echo Here's the proof... dir | find "Directory of" echo exiting...
This is the output I got
Starting master.bat I am master.bat I am stored in: D:\users\ I am running from: D:\users Running individual user batches... This is new_sendmail1.bat I am stored in: D:\users\george\ I am running from: D:\users\george Here's the proof... Directory of D:\users\george exiting... This is new_sendmail1.bat I am stored in: D:\users\joe\ I am running from: D:\users\joe Here's the proof... Directory of D:\users\joe exiting... This is new_sendmail1.bat I am stored in: D:\users\mike\ I am running from: D:\users\mike Here's the proof... Directory of D:\users\mike exiting... Back in master.bat Back in folder: D:\users Ended master.bat Press any key to continue . . .
Thank you!
|