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.
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.
Please also mark the comments that contributed to the solution of the article
Content-Key: 87416
Url: https://administrator.de/contentid/87416
Printed on: April 23, 2024 at 23:04 o'clock
2 Comments
Latest comment
salü
probier folgendes:
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
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