Sum of several text files *.txt

Asked

Viewed 1,395 times

3

I have a series of files in . txt and would like to add them / join all in one (Regardless of order).

It is possible to do this by word vba, some other text editor, or other means?

textos

1 answer

4


A relatively simple way is to use Windows CMD.

Using for + type:

cd /d c:\caminho\para\a\pasta 
for %f in (*.txt) do type "%f" >> amalgama.out

in place of amalgama.out you put the desired output name.

You don’t even have to make one .bat, just run right into prompt command.

Relevant information: I used .out in the output to avoid double concatenation (add the amalgama.txt in itself). Any extension other than .txt serves, but it is convenient to use one that is not "hidden" by Windows. Nothing that a rename do not solve at the end ;)


Using copy:

This is a simpler alternative, but it does not force line breaks at the end of each file. It can happen of "paste" two lines if the last of some file does not end with breakage.

cd /d c:\caminho\para\a\pasta 
copy /b *.txt amalgama.out

The /b indicates "binary", but can be used with .txts normally, to ignore any special character.

Of curiosity, the /d used in commands cd above serves to change drive if necessary while avoiding running cd c: and cd \caminho separately, in case the prompt is not open already in the correct unit.

  • 1

    It worked. Perfect! Thanks!

  • The /d in the cd did not know! Always forced to enter the unit vlw @Bacco

Browser other questions tagged

You are not signed in. Login or sign up in order to post.