0

I need a .bat file compatible from windows 7 to windows 10 which concatenates 2 files

For example

file1.txt:

hello

file2.txt:

world

After running the batch script, a new file called file3.txt will contain the contents:

hello
world

A newline should be added after the contents of file1

Mad Max
  • 11
  • 1

1 Answers1

1
type file1.txt file2.txt > file3.txt

Edit: Try this for the newline part:

echo. > newline.txt
type file1.txt newline.txt file2.txt > file3.txt
del newline.txt
  • In order to meet the requirement in the final paragraph you'd need to include, in that command, a newline.txt containing a newline - or equivalent. – RedGrittyBrick Jun 09 '16 at 15:16
  • Almost done! Output file is ciaomondo (helloworld) i need world under hello – Mad Max Jun 09 '16 at 15:20
  • I do not suggest following this advice. I believe that, with at least some versions, the TYPE command will corrupt the file if the file has ASCII code 26. The approach mentioned here will work just fine in some cases (including the sample files asked about), but not as many cases. For a variation that I believe will be more reliable, 'tis better to use `Copy/B` with pluses, as shown by [nik's answer](http://superuser.com/a/111827/401839) – TOOGAM Jun 10 '16 at 02:29
  • @Toogam do you have a source for that little tidbit? – Daniel Centore Jun 10 '16 at 02:34
  • Experimentation just indicated that this works fine in Windows 7 x64 CMD.EXE. I may be thinking of older code. [sample online reference](https://books.google.com/books?id=ZjO6CAAAQBAJ&pg=PA106&lpg=PA106&dq=dos+type+characters+after+ctrl-z+eof&source=bl&ots=Wl01WiduzW&sig=rkKqe1sAd-k8yMdJPwvSb_a2eQ8&hl=en&sa=X&ved=0ahUKEwiKuqGTu5zNAhURxWMKHdgQBWU4ChDoAQhMMAk#v=onepage&q=dos%20type%20characters%20after%20ctrl-z%20eof&f=false) discusses type. (Still, even if the threat seems outdated, I prefer to use techniques that seem safest. Back in the day, COPY/B was known to work safer about this issue.) – TOOGAM Jun 10 '16 at 03:01
  • Thanks to all reply. I need a more advanced batch. A batch not bound to the filename of the 2 imputs (file1.txt and file2.txt). I need to put the .bat to the folder and the user must simple click to create file3.txt (the edited @DanielCentore answer works i need an upgrade ;-) ) – Mad Max Jun 10 '16 at 07:22
  • EDIT the file1 and file2 are .mov not txt but the content is a text file. output file .txt is fine – Mad Max Jun 10 '16 at 07:27