Marcus Thornton
Marcus Thornton

Reputation: 6193

How to concatenate files with a new line between files in dos command line

I know I can concatenate files in a directory like:

copy /b *.txt all.txt

But I got one more question. How should I put new line between each files? I found that it's a problem for copy /b command. Think about this situation:

content of a.txt: --ALTER TABLE table1 ...;
content of b.txt: CREATE TABLE table2 ...;
content of c.txt: DROP TABLE table3 ...;

I hope the result of the concatenation will be

--ALTER TABLE table1 ...;
CREATE TABLE table2 ...;
DROP TABLE table3 ...;

instead of

--ALTER TABLE table1 ...;CREATE TABLE table2 ...;DROP TABLE table3 ...;

, in which the content could be regarded as a comment.

Upvotes: 5

Views: 10731

Answers (1)

Endoro
Endoro

Reputation: 37569

(for /f "delims=" %%a in ('dir /b /a-d *.txt') do (
    type "%%~a"
    echo(
  )
)>all.txt

Upvotes: 6

Related Questions