If you have a couple (or more) text files that you'd like to combine into one larger text file, Windows provides a few ways to do it. Which way you choose will likely depend upon how many files you want to combine, how big they are, and how comfortable you are with the different approaches.
One approach that may first come to mind is the copy/paste approach. This lets you stay within the familiar Windows environment while still accomplishing your goal. Follow these general steps:
Obviously, this is a very tedious approach—especially if you have more than a couple of files to be combined. The other approaches are much faster, but they do require that you do the work at the command line.
Probably the simplest command-line approach to use in combining files is to use the Copy command. With Copy, you can specify a number of files as inputs and one file as an output file. This will then copy all of the input files into the one output file, and you're done. Your command line might look something like this:
C:\> copy in1.txt + in2.txt + in3.txt Combined.txt
This will copy the files "in1.txt", "in2.txt", and "in3.txt" to a file called "Combined.txt". (The Combined.txt file is automatically created by the Copy command. If Combined.txt previously existed, it is overwritten by the command.) The Copy command supports wildcards, too, so if your file names follow a standard format, you could even do it this way:
C:\> copy in*.txt Combined.txt
This is probably the best approach to take, but if you prefer a more esoteric solution you could try either of two variations of the Type command. For example,
C:\> type in*.txt > Combined.txt
This types the contents of all of your "in" text files and sends the output to your "Combined.txt" file. If the Combined.txt file previously existed, it is overwritten by this command.
The second variation of the Type command also uses the For command. In this variation, the "in" files are cycled through one at a time and their contents are appended to your "Combined.txt" file:
C:\>For %f in (in*.txt) do type %f >> Combined.txt
These are all interesting ways to attack the problem, but my favorite is the simple Copy command.
This tip (5670) applies to Windows 7, 8, and 10.
The DiskPart utility is a low-level command-line program that lets you manage disks, virtual disks, partitions, and ...
Discover MoreGraphics files have additional attributes that other files don't have. This tip describes how you can display these ...
Discover MoreThere are a few ways to set up a copy schedule in Robocopy by using its options. This tip explains how.
Discover More2023-04-10 06:35:22
amit
Really helpFul... saved lot of time.. thanks
2022-11-20 10:22:08
sandeep kothari
This is amazing Barry!
2022-11-19 07:46:41
Wow. This has helped me a lot. Thank you very much.
2022-08-29 02:35:28
Ioan
You can simple use Python for this job, as below:
---------------------------------------------------------------
import shutil
import os
import glob
filenames = glob.glob('*.txt')
with open('output_file.txt','wb') as wfd:
for f in filenames:
with open(f,'rb') as fd:
shutil.copyfileobj(fd, wfd)
2022-05-19 12:17:12
80 txt combined in a second. thanks a lot!
2021-04-15 12:50:52
Arun
 I am getting this word before starting of line after copying.
Is there any solution to trim this.
Error comes in Ansi Format only
2021-03-14 11:20:10
My problem: How to merge a bunch of TXT files (e.g., account info) for printout as a single document, using Notepad.
Having cut my programming teeth in the age of DOS/360, I found Barry's Command-Prompt approach appealing. And, after a couple false starts, I was able to get this to work: C:\Users\WN>copy G:\Files\*.txt MergedFileName.txt .
But, two glitches: 1) The MergedFileName.txt was written, not to the G: drive as I had wanted, but to C:\Users\WN. So, I had to go find and move it, manually. Not a big deal, but just another step.
2) The many *.txt files in the folder "Files" were merged, not alphabetically by component-file name as I had wanted, but by the component files' times of creation. Just moving the *.txt files to a new folder before merger didn't help, because Windows, in its wisdom, insisted on ordering by time of file creation, not time of most recent modification. So, the only way I could find to alphabetize component files within MergedFileName.txt, was to go back to the original set in "Files" and rename and resave so that re-creation-time order = alphabetic order. Surely, there is a better way??
2020-06-23 21:02:06
Timothy Takemoto timtak
Thank you. Copy worked for me. I could not change directory in the command prompt to my external SD Card so I copied my text files to C:\Users\MyUsername> which is where the command prompt defaulted to.
2020-03-27 13:07:53
Kam Mistry
Great post! Very helpful.
2020-03-07 12:55:31
walki
this wasn't helpfull what about you can make a TIP on how to combine mutiple files into a single file on Windows 10 Home Edtiton
2019-12-24 10:53:07
J. Woolley
@John Fielding
Open a command prompt in the parent folder of the branch001 folder (i.e., the parent of all branch* folders) and try this:
DEL CombineGLT122019.XMT 2>NUL
FOR /F %f IN ('DIR /B branch*') DO TYPE %f\GLT122019.XMT >>CombineGLT122019.XMT
2019-12-23 16:46:18
John Fielding
Great write-up, Barry. How would I code the iterative copy if my file structure is more like: branch001\GLT122019.XMT, branch002\GLT122019.XMT, \branch003\GLT122019.XMT etc etc etc, and I want all of the data from each branch's file merged into one XMT (or TXT) document? I'd like to wildcard the branch node since we frequently add branches. I've been experimenting with copy, for/copy, and xcopy for days and cannot get it to work.
Copyright © 2024 Sharon Parq Associates, Inc.
Comments