views:

34

answers:

2

I'm trying to use the following batch script to concatenate some files together:

copy NUL bin\translate.js
for %%f in (source\Libraries\sprintf.js, source\translate-namespace.js, source\util.js, source\translator.js, source\translate.js) do (
    type %%f >> bin\translate.js
    echo. >> bin\translate.js
)

However, when I do this, an extra character seems to be printed at the end of each file. When I view the file in ASCII, it is interpreted as these three characters: 

Why is this happening? What can I do to fix it?

A: 

The DOS copy command works like the UNIX cat command. That is, you can list multiple source files and one destination file, seperated with + signs.

copy source\Libraries\sprintf.js+source\translate-namespace.js bin\translate.js
eduffy
I am aware that this is possible, but I wanted to add a new line in between concatenated files. Also, this has the exact same problem.
Steven Oxley
Well, you already have a `NUL` file, which I assume is empty. You could have a "one blank line" file and insert that along with the source files.
eduffy
+1  A: 

The  looks like a unicode byte order mark. Is it possible to start with files that are stored without the byte mark? I am not aware of any command line commands that can remove the mark.

Martin Brown
Good call. It looks like this is, indeed, the problem. I will look into seeing if I can store the files without the byte order mark, but I don't know if that's feasible (other people could possibly be editing the files and I'd like for them to be able to edit the files in the editor of their choice).
Steven Oxley
This would of course be very easy to do if you used a programming language other than Windows batch files.
Martin Brown
Agreed. Fortunately, I was able to find a tool that would do what I wanted without me having to write anything (as much fun as that would be, it's not exactly how I wanted to spend my time). The tool can be found here: http://www.interworks.com/blogs/banderton/2010/04/01/javascript-combinerbuilder
Steven Oxley