1.

Solve : Help in batch file?

Answer»

Hi everyone!...and sorry my english..
I'm a new user of this forum, and i need your help, please.

My problem is:

(imagine that i have 10 folder's...folder1, folder2, etc..each one with 2 files: log.txt and prog.exe (prog1.exe, prog2.exe, etc, depending on the folder's name))

I need a batch file that verify that folder1 exists..
If exist then verify if the file log.txt has the string "100%".
If the folder exist and the string is not "100%", then start prog1.exe, but if prog1.exe is allready running, go AHEAD to the next folder.

Also i need to, say hourly, verify is if the log.txt of the running prog.exe has allready the string "100%" in it. If so, close the prog.exe and go on to the next folder.

And so on...looping all the folder's and back to folder1...and so on.

I hope u can help me here...thanks!
This TESTS existence of folder1, folder2, etc.

Code: [Select]if exist folder1 (
(insert code)
)

if exist folder2 (
(insert code)
)

if exist folder3 (
(insert code)
)
this can work:
Code: [Select]setlocal enabledelayedexpansion
set folderArray=folder1 folder2 folder3 folder4 folder5 folder6 folder7 folder8 folder9 folder10

for %%a in (%folderArray%) do (
if exist %%a (
type %%a\log.txt |findstr "100%%"

if !errorlevel! equ 1 (
tasklist /V >nul |findstr "prog1.exe" || prog1.exe
) else (
taskkill /IM prog1.exe
)


)
)
pauseThanks for the help!

I kind of arrange some code that work for me, but i guess its a little mess, take a look please:



Code: [Select]:start

if exist folder1 goto loop1

goto Continue1



:Loop1

find /i "100%%" folder1\unitinfo.txt
if %errorlevel% EQU 0 (goto Continue1)
tasklist.exe /FI "IMAGENAME eq fah1.exe" 2>NUL | find.exe /i "fah1.exe" >NUL || GOTO START1
ping -n 300 127.0.0.1 >NUL
GOTO Loop1
:start1
cd cfolder1
start fah1.exe
GOTO Loop1
:Continue1
TASKKILL /F /IM "fah1.exe"


if exist folder2 goto loop2

goto Continue2


:Loop2
find /i "100%%" folder2\unitinfo.txt
if %errorlevel% EQU 0 (goto Continue2)
tasklist.exe /FI "IMAGENAME eq fah2.exe" 2>NUL | find.exe /i "fah2.exe" >NUL || GOTO START2
ping -n 300 127.0.0.1 >NUL
GOTO Loop1
:start2
cd folder2
start fah2.exe
GOTO Loop2
:Continue2
TASKKILL /F /IM "fah2.exe"

'and so on until folder 10 (folder1, folder2, etc..)

goto start


The only thing i need now is to, at the end, before the last loop (goto start), check in every 10 folder's if all unitinfo.txt has a string with "100%"..if so Exit.

Thanks again!
why you want to make code for each folder ?

try now:

Code: [Select]setlocal enabledelayedexpansion
set folderArray=folder1 folder2 folder3 folder4 folder5 folder6 folder7 folder8 folder9 folder10
set cout=0

for %%a in (%folderArray%) do (
set foldNum=%%a
set foldNum=!foldNum:~-1!
if !foldNum! equ 0 set foldNum=10

if exist %%a (
type %%a\log.txt |findstr "100%%"

if !errorlevel! equ 1 (
tasklist /V >nul | findstr "fah!foldnum!.exe" || %%a\fah!foldnum!.exe
) else (
taskkill /IM fah!foldnum!.exe
)

call :CheckAll

)
)
pause
exit


:CheckAll
for %%a in (%folderArray%) do (
type %%a\log.txt | findstr "100%%" && set /a cout+=1
)
if %cout% equ 10 exit
exit /bHi there!!

Well, is almost perfect!!..
I made the code for earch folder because i'm not used to code...i saw some code samples and try to arrange them at my need...

To work perfectly, i just need two more things:

1- verify in every 30 minutes (for example) the log.txt of the current running aplication "fah!foldnum!.exe", to SEE if has allready the string "100%". (before check the next folder)

Like this Code: [Select]:Loop1

find /i "100%%" folder1\unitinfo.txt
if %errorlevel% EQU 0 (goto Continue1)
tasklist.exe /FI "IMAGENAME eq fah1.exe" 2>NUL | find.exe /i "fah1.exe" >NUL || GOTO START1
ping -n 300 127.0.0.1 >NUL
GOTO Loop1


2- i also need this code in it, to run aplication:

Code: [Select]cd folder1
start fah1.exe

I've tryed to modify your code with this things but wont work..
May i ask one more BIG help with this?
Tanhks


Sorry..
Can anyone help me here, please?
Thanks a lotCode: [Select]@echo off & setlocal enabledelayedexpansion
>sleep.vbs echo wsh.sleep 10000 ^'ms

pushd "c:\program files\[emailprotected]"
for /d %%a in (work*) do (
echo [%time%] %%~dpna

pushd %%a
set f=&for %%b in (*.exe) do set f=%%b

if exist unitinfo.txt if defined f (
find "100%%" unitinfo.txt>nul && (echo taskkill !f! here)||(
tasklist|find "!f!">nul||echo start !f! here)
)
popd
)
popd

for %%a in (cscript//nologo del %0) do %%a sleep.vbs



Discussion

No Comment Found