Link to home
Start Free TrialLog in
Avatar of morinia
moriniaFlag for United States of America

asked on

Concatenating multiple text files into one file

If I have multiple text files in a folder (Folder A).  Does any one know through Windows scripting how to concatenate them into one file without maually cut and pasting?

Example
Text1.txt
Text2.txt
Text3.txt                         to                     Text4.text (which has all the files)
ASKER CERTIFIED SOLUTION
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of klodefactor
klodefactor

I typically don't type spaces around the plus signs, to make it easier to see where the target file name starts.

If there's any chance of non-ASCII characters in one of the files, use the /b option for the copy command:
copy/b Text1.txt+Text2.txt+Text3.txt Text4.text.
If any file name contains one or more spaces, remember to surround the name with double quote characters ("):
copy/b "file name one.txt"+Text2.txt+Text3.txt Text4.text.
--klodefactor
Avatar of Steve Knight
You can also do

copy c:\someotherdir\*.txt C:\alldir\all.txt
(as otherwise all.txt would be included in the output!)

or
type c:\somedir\*.txt > c:\alldir\all.txt

or if you want a little header saying which file it is:

find /v "something-not-in-any-file zxzxcvbz" *.txt > all.txt