views:

8822

answers:

5

Hello. I need to join to binary files in *.bat script on Windows. How can I achieve that?

+13  A: 

You can use copy /b like this:

copy /b file1+file2 destfile
Greg Hewgill
+1  A: 

Just use the dos copy command with multiple source files and one destination file.

copy file1+file2 appendedfile

You might need the /B option for binary files

simon
+10  A: 

type works similar to cat.

type file1 file2 > file3

Edit: Greg, can you explain what you mean by file headers? (I would just comment but I don't have enough karma yet)

Edit2: The file headers are printed to stderr, so the redirect to the output file works like cat, at least in Windows XP.

Nathan Jones
The problem with type in this situation is it adds unwanted file headers when typing more than one file specified on the command line.
Greg Hewgill
When specifying more than one file on the command line, type outputs a few blank lines and the name of the file, before copying the contents of the file. Try it :)
Greg Hewgill
Ah, I hadn't noticed that the headers go to stderr. Good to know.
Greg Hewgill
+1  A: 

Shameless PowerShell plug (because I think the learning curve is a pain, so teaching something at any opportunity can help)

Get-Content file1,file2

Note that type is an alias for Get-Content, so if you like it better, you can write:

type file1,file2
Jay Bazuzi
+2  A: 

If you have control over the machine where you're doing your work, I highly recommend installing GnuWin32. Just "Download All" and let the wget program retrieve all the packages. You will then have access to cat, grep, find, gzip, tar, less, and hundreds of others.

GnuWin32 is one of the first things I install on a new Windows box.

David Citron
I would recommend GetGnuWin32 (to simplify installation)
J.F. Sebastian