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

Ausgedruckt am: 19.03.2024 um 02:03 Uhr

Mitglied: 129813
Lösung 129813 16.08.2016 um 21:07:37 Uhr
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
Mitglied: Peter32
Peter32 17.08.2016 um 13:33:58 Uhr
Goto Top
Danke! face-smile
Mitglied: Peter32
Peter32 06.09.2016 um 15:14:19 Uhr
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 06.09.2016 aktualisiert um 16:32:24 Uhr
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.