This question is similar to cmd is somehow writing chinese text as output.
The text files are Unicode text files, most likely with UTF-16 little endian encoding.
To get Unicode text file file1.txt correct appended to Unicode text file file2.txt using command type
it is necessary to start command line interpreter cmd.exe
with the switch /U
to get output of internal commands redirected into a file or piped to another command in Unicode format.
As Aacini suggested already correct, the command line to use is
cmd /U /C type file1.txt >> file2.txt
Another method for concatenating 2 or more text files is to use the copy command.
copy "Text File 1.txt" + "Text File 2.txt" + "Text File 3.txt" "Output File.txt"
It is not necessary to call cmd.exe
with switch /U
in this case even if the text files are encoded in UTF-16 instead of ANSI.
The command copy
automatically removes byte order mark (BOM) of Text File 2.txt and Text File 3.txt if all 3 text files are Unicode text file with a BOM. Output File.txt contains in this case just once the BOM at beginning.
copy *.txt "Output File.txt"
concatenates all text files in a directory to a file with name Output File.txt.
Note 1:
NTFS file system driver returns the list of *.txt files in a directory always in alphabetic order (not alphanumeric!) according to file name. Therefore the file names determine on NTFS partitions the order of concatenation of the text files. But FAT32 file system driver returns the list of *.txt files in a directory according to listing in the file allocation table which results in an unpredictable order of concatenation of the text files on a FAT32 partition if using above command with *.txt
.
Note 2:
It is important on usage of command copy
that all text files have the same encoding, i.e. all text files are UTF-16 encoded or all text files are ANSI encoded.
Note 3:
Command copy
can be also used to concatenate binary files. Enter in a command prompt window copy /?
or help copy
for a short help explaining also the optional switches /B
(binary file) and /A
(ASCII/ANSI text file).