peter32
Goto Top

Mittels Batch jede Zeile einer Textdatei prüfen

Hallo,

ich habe eine Textdatei (Projekte.txt), die etwa so aufgebaut ist

Unbekannter Text 1
Unbekannter Text 2
Unbekannter Text 3
usw...

Nun möchte ich gerne, dass ein Batch-Script jede Zeile dieser Textdatei einliest und für jede dasselbe andere Batch-Script ausführt. Ungefähr so:

Lese 1. Zeile ein und gebe sie in Variable %INPUT% aus.
Nun starte das Script, das öfters auf diese %INPUT% variable zugreift.

Sobald das Script durchgelaufen ist, 
Lese 2. Zeile ein und gebe sie in Variable %INPUT% aus.
Nun starte das Script, das öfters auf diese %INPUT% variable zugreift.

Sobald das Script durchgelaufen ist,
mache dasselbe, bis alle Zeilen durchgelaufen sind und fange wieder von oben an.

Ich habe schon probiert:

for /f "usebackq" %%v in ("Projekte.txt") do goto inputscript & set "INPUT=%%v"  

aber ich glaube ich missverstehe den code etwas bzw. er funktioniert nicht.

Hat jemand eine Idee, wie ich das elegant lösen könnte?

Danke im Voraus!

LG
Peter

Content-Key: 312776

Url: https://administrator.de/contentid/312776

Printed on: April 23, 2024 at 10:04 o'clock

Mitglied: 129813
Solution 129813 Aug 16, 2016 at 19:07:37 (UTC)
Goto Top
@echo off & setlocal
for /f "usebackq delims=" %%a in ("C:\projekte.txt") DO (  
	call :myscript "%%a"  
)
goto :end

:myscript
echo Do something with line '%~1'  
goto :eof

:end
pause
Regards
Member: Peter32
Peter32 Aug 17, 2016 at 11:33:58 (UTC)
Goto Top
Danke! face-smile
Member: Peter32
Peter32 Sep 06, 2016 at 13:14:19 (UTC)
Goto Top
Hello highload,

I've created a new topic For Schleife kaputt? and I've build a bit more advanced script based on your suggestion here:
@echo off & Setlocal
:Begin

if exist "Started.txt" del "Started.txt" /s /q >NUL  
dir /od /b "Started">"Started.txt"  
for /f "usebackq delims=" %%a in ("Started.txt") DO (   
	call :ForEveryStarted "%%a"   
) 
goto :end

:ForEveryStarted

echo %date% %time% Programm ist gerade bei "ForEveryStarted".  
if exist "name.txt" del "name.txt" /s /q >NUL  
echo %~1>"name.txt"  
echo Die Zeile heisst: %~1
set "StartedProject="  
set /p "StartedProjekt="<"name.txt"  
:end
pause

I don't understand the suggestion from Pjordorf with the enabledelayedexpansions and you also didn't have it in your code from the beginning, it would be awesome if you can comment on the new topic, too face-smile
Mitglied: 129813
129813 Sep 06, 2016 updated at 14:32:24 (UTC)
Goto Top
You should read this
Tutorial zur FOR-Schleife
for Delayed Expansion, that's because you store variables which are only expanded at runtime.