How to combine several text files into one. Combining several files into one without the help of special programs. How to combine files into one

Often a situation arises when it is necessary to merge several audio or video files into one file. or combine many text files into one common file. It turns out that this can be done without any special programs, only using Windows tools. Let's assume that you need to merge an audiobook consisting of many mp3 files into one mp3 file. First, make sure that all files are numbered correctly, since gluing occurs exactly in the order of file numbering. It is best for files to be numbered as 01, 02, and so on. then the gluing will be done exactly in the right order. Now, in the folder with these files, create a regular text file named “merging media files.txt”. In this file write the following line:

copy /b *.mp3 "C:\United file.mp3"

then save the file and change the txt extension to cmd. now just press Enter on this file, all files will be merged into one mp3 file, and the combined file will appear on the C: drive. Naturally, you can specify any other path in the batch file instead of drive C:. however, Russian letters cannot be used in the name of the final file. It’s better to rename it as you need after gluing it together. This file is good because it only merges all mp3 files in the folder in which you launched it; it ignores any other types of files. similarly, you can use the same file to merge video files, say avi, mp4, wmv formats, and so on. Only in the text of the file change the extension mp3 to avi or something else you need. To quickly edit the file Merging media files.cmd, simply open the context menu of this file (right-click on it) and select “Edit”. the file will open in Notepad and you can make the changes you want.

To merge multiple text files into one, first make sure there is a blank line at the end of each text file you want to merge into one. If it's not there, be sure to add it. This is necessary so that after gluing, the text of each merged file begins on a new line, and not directly after the last character of the previous file. then, correctly number all the text files and create the Text Glue.cmd file in the folder with these files, as described above. In the text of the file, enter the following:

copy /a *.txt "C:\United Text.txt"

and save the file. after running this file, a final file should appear on drive C: containing the text of all merged files. The example is given for txt files, but you can specify another extension, say doc, rtf or docx, if you are merging text files of the appropriate format.

It happens that you need to combine the required number of files into one using standard Windows tools. Few people know that such functionality is available in any edition of Windows with just 1 line of code. You can merge files of any test content, for example *.txt, *.css, *.js and any others. It is very convenient to automate the workflow without routine manual work.

How to combine files into one

In this case, the copy command will help us cope with this task. Let's imagine that we need to combine several css files of our website into one file:

Copy "*.css" /b "style.css"

The /b parameter is necessary so that the files are combined as binary ones, otherwise an extra character is added at the very end of the file. The copy command contains many other options. You can get the entire list by running the command copy /? but the /b key is enough for us.

The files are merged in the order in which they are visible using the dir command. If the order of the files is important, you must first rename them by adding a digital index to the beginning of the file.

Hello, friends. Lately you have often asked me how to combine txt files into one. We’ll talk about that at bedtime (I don’t know about you, but it’s already dark outside my window). Inspired, I have selected for you some of the simplest and most effective methods for Windows and other operating systems.

You can combine small txt files into one large document in different ways - by writing scripts in bat files or commands in the cmd line. And also all kinds of programs will come to the rescue.

Concatenation

Among the huge number of requests received on this topic, there was also the question: “what is concatenation of text files?” Concatenation (sounds mysterious, really) is nothing more than combining several documents of a given format into one, that is, sequentially transferring the contents of all documents into one, placing them directly next to each other.

Imagine you have a lot of txt files (to understand the essence, let’s look at example 3):

  1. The first one says MOM.
  2. In the second - DAD.
  3. And in the third - I.

After concatenation, you will receive only one document with the text MAMAPAPAYA, which is the essence of the whole process. Of course, correctly selected solutions to achieve your goals imply the possibility of adding separators - spaces or lines - between the added fragments.

A reasonable question arises: “why is this necessary?” For example, combine chapters located in separate files into one book. Or collect monthly reports into one annual one. There can be countless situations.

Windows

First, I’ll tell you how to combine several existing txt files into one in Windows, which is native and familiar to many. Then we will briefly discuss solutions for some other operating systems. So, in the system created by Microsoft, there are several ways to quickly combine all given piece files into one whole text “pie”.

Online services

The most hassle-free way to combine the required txt files into one file, in my opinion, is to use one of the many online services. I have tested and positively evaluated the Filesmerge resource, the functionality of which allows you to merge not only “text files”, but also JPG, PDF, Word and Excel files. And txt-pies can be obtained not only from sources of the same format, but also from text, lst, log, euc, me, err, ans, dsc, asc and eml-pieces (I might have missed a couple of formats). To merge you need:

  1. Select files from your computer or the Internet, for which the corresponding windows are provided.
  2. Configure the nuances of merging in the form of adding suffixes, prefixes and delimiters, as well as confirming the output format.

Bat file

Although offers of online services are tempting with their simplicity, they are not interesting for me, since I prefer to solve problems on my own. In this case, I am more interested in combining scattered txt files into one common one by creating a bat file with the appropriate command. For example, like this:

  1. Given: 2 files – 1.txt and 2.txt.

  1. The first contains the contents of MAMA.

  1. In the second - DAD.

  1. Let's create another text file (I'll call it 9.txt) using a standard Windows tool called Notepad.

  1. Enter the command into it:

copy /b 1.txt + 2.txt ITOG.txt

    1. Using “File” we save the document as 9.bat.

  1. Close Notepad and see that a batch file named 9.bat has appeared in the folder.

  1. We launch it and reap the benefits in the form of the disappeared 9.txt and the appearance of ITOG.txt.

  1. We open ITOG.txt and find a merger of two texts MAMAPAPA.

The script we wrote commands the system to perform a task from 9.txt, namely to add the contents of 1 and 2.txt, write it to ITOG.txt, and delete 9.txt upon completion.

Merging files through bat documents is quite a simple and interesting task if you know. Possible spelling options:

  1. Same result: copy *.txt all.txt
  1. Divided into parts:

Having opened final.txt obtained from the last script, we will see the contents of the source code, written in a column.

I am sure that professionals in this field could write many scripts, but the ones I have given are already quite enough to achieve the goal.

Command line

Those who like to “command” the system will definitely be interested in how to connect the same text (txt) files using the command line. I would like to separately note (for those who asked), MS DOS is the internal Windows environment and all actions in it are performed through the command line (which means this method is suitable for you too). In order to combine txt files into one, you need to launch a window of the same line by typing cmd in “Run” (found in “Start”).

As a result, a black window should appear asking the system to enter a command, which is what we will do next.

The command is simple, it includes ACTION PATH TO FILE 1 + PATH TO FILE 2 PATH TO RESULT. My files 1 and 2.txt are located on drive E, I want to put the result there too, so we write copy E:\1.txt + E:\2.txt E:\3.txt

To confirm the action, press Enter and see a report on the successful completion of the task.

To check the result, I will go to drive E, and you will go to the path that you specified in the command. As a result, I saw a new document 3.txt, and in it the combined contents of the specified files. Did you succeed? (write in the comments).

Friends, if you prefer to work in Powershell, then there you can easily combine text files with the same command, but with a small addition of cmd /c copy E:\1.txt + E:\2.txt E:\3.txt

After confirming the action with “Enter”, the result will not take long to arrive.

Programs

I understand that not all users share my passion for writing commands and scripts, and therefore I have prepared alternative methods for you, namely through all kinds of software - special programs, file managers and text editors.

Managers

I received many messages about how convenient, wonderful and multifunctional the Total Commander manager is (I admit, I don’t like it), so they can also easily combine txt files into one:

  1. Select the first “piece” in the folder.
  2. Go to the “File” menu and run the “Assemble...” action (in older versions “Glue”).
  3. Specify the path to the future “pie” and click OK.

  1. Select sources.
  2. Press the F5 key.
  3. Come up with and write a name for the future document.
  4. From the list of existing files, select “Add”.
  5. Confirm with the Enter key.

Programs

Friends, first, let’s talk briefly about Notepad ++, you can also combine files in it, but for this you will have to install a special Combine plugin. It will allow you to glue the selected “pieces” together, add names to them and insert lines between them.

I can say a lot of good things about the TXTcollector program. It helps you comfortably achieve what you want, but you will have to install it on your PC, after which all you have to do is hide all the “pieces” in one directory, specify the path to that folder in the program, set the name of the future “pie” and the location where it will be saved, configure the presence of divisions (dashes or other symbols) and press the Combine button... to start gluing.

I can also mention the programs File Joiner and WinMerge (the same principle), and the latter allows you not only to merge files, but also to compare their contents.

Other OS

As promised, we’ll briefly look at merging text files in other operating systems, for example, for Mac OS I know the DiffMerge program, which also allows you to compare and merge documents. And in the same OS, several small files can be turned into one large one by using the textutil utility (launched through the terminal) and the cat command.

You can also combine scattered txt files into one common one in Linux. This happens in approximately the same way as through the command line in Windows. Only in Linux the “executor” of commands is called “Terminal”, and in it you need to enter the phrase cat name1 name2...names of all the name of the output document. If we adapt it to our case, it will look something like cat 1.txt 2.txt itog.txt.

Concluding the story, I would like to say a few encouraging words to inexperienced users who decided to figure out on their own what “concatenation” is. Go for it! Well done! Mysterious and incomprehensible concepts look scary only at first glance. In reality, they can mean something completely harmless, for example, concatenation is a banal combination of files. Writing scripts and commands for cmd is also not difficult if you know the basic principles. And you can figure out any program in just 5 or 10 minutes. The main thing is your unshakable desire, thirst for new knowledge and a bit of stubbornness.

The story turned out to be quite long, but I hope it was useful. Goodbye.

Team COPY used to copy one or more files in the Windows command line.

Command line format:

COPY source [+ source [+ ...]] [result]

source- The names of one or more files to be copied.

/A- The file is an ASCII text file.

/B- The file is a binary file.

/D- Indicates the possibility of creating an encrypted file

result- Directory and/or name for the target files.

/V- Checking the correctness of file copying.

/N- Use short names if possible when copying files whose names do not comply with the 8.3 standard.

/Y- Suppress confirmation prompt to overwrite existing target file.

/-Y- Mandatory confirmation request to overwrite an existing target file.

/Z- Copy network files with resume. Key /Y can be set via environment variable COPYCMD.

Key /-Y command line overrides this setting.

By default, confirmation is required to overwrite existing files unless the command COPY is not executed in a batch file.

Team copy allows you to combine several files into one. To combine files, specify one target and multiple source files using wildcards or the format "file1+file2+file3+...".

By default, files are copied as one-to-one binary files, so the option /B you don't have to ask. Parameter /A necessary if special characters used in text files must be processed in the copy results.

Key /N used for compatibility with MS-DOS programs that do not support long file names.

Examples of using COPY:

copy/?- issue a certificate about the use of the command.

copy file1.txt file2.txt- copy file file1.txt to file file2.txt in the current directory. If the file file2.txt exists, the user will be prompted to confirm whether to overwrite the existing file.

copy /Y file1.txt file2.txt- the same as in the previous example, but you are not prompted to confirm whether to overwrite an existing file.

copy *.txt D:\oldfiles\*.txt- copying all files with the extension txt from current directory to directory D:\oldfiles

copy file1.txt + file2.txt +file3.txt file123.txt- copy the contents of files file1.txt, file2.txt And file3.txt to file file123.txt

copy C:\ndldr "D:\My Backup\system\ntldr"- When using file or directory names containing spaces, double quotes are used.

COPY /V file.bin A:\saved.bin- copy the file to a floppy disk A: with checking the result.

    Team COPY can be used to copy files using standard I/O devices:

Copy con myfile.txt- copying from device con(console, console) to file myfile.txt- i.e. Entering characters directly from the keyboard into a file. End-of-file is used to terminate input. CTRL+Z(or pressing F6)

copy NUL newfile.txt- copying from a dummy device nul to a file, i.e. creating an empty file named newfile.txt

copy movie.avi nul- copy the file to a dummy device nul, i.e. simply reading a file, sometimes used as a means of testing storage media.