xymit1
Goto Top

Dateinamen als Variable in Schleife übergeben, Inhalt von Dateien wegschreiben

Hallo, ich benötige eure Hilfe

Ich habe in einem Ordner einige Textfiles, mit x-beliebigen Inhalt.
Ich möchte mit einer Batchdatei die Inhalte der Textdateien auslesen und in eine "Gesamtdatei" wegschreiben.
Bisher habe ich folgendes, mit dem ich aber noch nicht das gewünschte Resultat erhalten habe.

@echo off
For /F %%i in ('dir /b /A:-d /o:d "*.txt"') do call :loop2 "%%i"
goto :eof

:loop2
for /f "tokens=*" %%k in ("%%i") do echo %%k >> gesamt.txt
goto :eof

Bsp.:
Auto1.txt => Inhalt: Auto1:xyz
Auto2.txt => Inhalt: Auto2:xyz
Auto3.txt => Inhalt: Auto3:xyz
Auto4.txt => Inhalt: Auto4:xyz
Auto5.txt => Inhalt: Auto5:xyz

Ergebniss muss sein: gesamt.txt mit folgendem Inhalt:
Auto1:xyz
Auto2:xyz
Auto3:xyz
Auto4:xyz
Auto5:xyz

Ich hoffe ihr könnt mir weiterhelfen.

Content-Key: 87416

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

Ausgedruckt am: 28.03.2024 um 22:03 Uhr

Mitglied: tacker
tacker 12.05.2008 um 13:25:08 Uhr
Goto Top
salü

probier folgendes:

@echo off
For /F %%i in ('dir /b /A:-d /o:d "*.txt"') do call :loop2 %%i  
goto :eof

:loop2
for /f %%k in (%1) do @echo %%k >> gesamt.txt
goto :eof

zu beachten ist, dass die variable %%i in der methode loop2 nicht mehr über den variablennamen sondern als ersten übergebenen parameter (%1) aufgerufen wird!

gruss tacker
Mitglied: xymit1
xymit1 12.05.2008 um 15:36:40 Uhr
Goto Top
Danke für die schnelle Antwort => funktioniert super!!!