jmituzas
jmituzas

Reputation: 603

.bat Merging header.txt to all *.txt files

I have a file called header.txt I want this file to be prepended (first line) to all *.txt files in the same directory.

How could I achieve this?

Thanks in advance, Joe

Upvotes: 0

Views: 500

Answers (2)

Michael
Michael

Reputation: 9068

@echo off
for %%x in (*.txt) do call :merge %%x
goto :eof

:merge
copy header.asc + %1 %1.new
del %1
ren %1.new %1
exit /b

Don't call the file header.txt though, because you don't want to prepend the header to itself (that's why I called it header.asc).

Make a backup before trying ;)

Upvotes: 4

Pavel Radzivilovsky
Pavel Radzivilovsky

Reputation: 19114

use for loop, and then copy + command.

See copy /? for copy + syntax.

See for /? for for syntax.

Upvotes: 1

Related Questions