top of page

Windows Command to Combine Multiple Text Files and Insert the File Names at the Beginning of the Con

This is a demonstration of a a simple script you can run in Windows command prompt to combine multiple text files and add the file names of each to where each source file begins. See my how to video posted to YouTube:

1. In the folder with your source files, press CTRL + SHIFT and right click. Then chose 'Open command window here'.

2. In command prompt, type:

findstr "^" *.txt

and then make reference to a new folder where you will write a new text file merging the source files together.


Press return to run the script. So the full script is just:

findstr "^" *.txt >C:\Process\output2.txt

3. The new text file that is generated will combine the full contents of the source files, and add in the file names at the beginning of each file's content.

If the original text file had line breaks, the file name will be added at the beginning of each line. If not, it will just be added at the beginning of the file's contents.

An example of where this command would be useful is a case where you want to add the text from emails to a new column in a spreadsheet to which you've exported the metadata for those emails.

bottom of page