
Ich versuche, eine Batchdatei zu erstellen, die alle 3 Minuten die Taskliste ausführt und sie in log.txt protokolliert. Ich bin ein Neuling im Umgang mit Batchdateien und würde gerne wissen, was ich in meiner Batchdatei falsch gemacht habe.
@echo off
set "CURRENT_DIR=C:\Documents and Settings\Administrator\My Documents\Downloads\"
:checkLog
if exist "%CURRENT_DIR%\log.txt" goto writeLog
echo Log file exists. Appending data.
if not goto createLog
:createLog
echo Creating log.txt
echo >"%CURRENT_DIR%\log.txt"
:writeLog
tasklist >> "%CURRENT_DIR%\log.txt"
goto loop
:loop
sleep 3
goto writeLog
Antwort1
Ich glaube, diese Zeile ist unvollendet:
if not goto createLog
Ich habe es ein wenig vereinfacht und timeout
stattdessen verwendet sleep
:
@echo off
set "CURRENT_DIR=C:\Documents and Settings\Administrator\My Documents\Downloads\"
if not exist "%CURRENT_DIR%\log.txt" (
echo Creating log.txt
echo >"%CURRENT_DIR%\log.txt"
) else (
echo Log file exists. Appending data.
)
:writeLog
tasklist >> "%CURRENT_DIR%\log.txt"
timeout /t 3 > nul
goto writeLog