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

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

Member: tacker
tacker May 12, 2008 at 11:25:08 (UTC)
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
Member: xymit1
xymit1 May 12, 2008 at 13:36:40 (UTC)
Goto Top
Danke für die schnelle Antwort => funktioniert super!!!