Windows – Any way to add new line at end of multiple text files

batchcommand linewindows

I am merging (concatenating) many text files into one,
but I have the problem that they don't have a new line at the end of the text.

Is there any way to append a new line to all files using Windows command or batch file?

I am using cmd.exe of Windows Vista.

Best Answer

You can run this as a batch file

del merged.txt

for %%I in (*.txt) do (
    echo %%~fI >> merged.tmp
    echo ------------- >> merged.tmp
    type "%%I" >> merged.tmp
    echo. >> merged.tmp
    echo. >> merged.tmp
)

ren merged.tmp merged.txt

This way you don't have to specify the names but all the files must be in the same folder.

The echo %%~fI echo the full path name, for other options you can consult

help for

Other than that, if the result is not exactly as you want, probaby all you need is just changing what are echo-ed

Related Question