Quick way to concatenate 100+ text files and IN ORDER?

Page 1 of 1 [ 3 posts ] 

skysaw
Veteran
Veteran

User avatar

Joined: 26 Mar 2008
Age: 46
Gender: Male
Posts: 645
Location: England

30 May 2012, 4:26 pm

How do I take a folder of 100+ text files and quickly concatenate them in order?

I know that if you put them in the same folder and type copy/b *.txt newfile.txt into the command prompt, it concatenates them into a new file, but the order seems to be random.

On the other hand, if you type copy/b file1.txt +file2.txt +file3.txt file4.txt into the command prompt, this will concatenate your files in the order you want, except typing out the names of 100+ files would take ages.

So what you could do then is highlight all your files and rename the top one, calling it, for example "file.txt". This will then rename the whole bunch as "file (1).txt", "file (2).txt" etc. Then you could create the text for your sum (e.g., file (1).txt + file (2).txt + ... etc) in Excel or something.

But ... but ... the command prompt does not recognise filenames with spaces in. So it then seems you would have to use the equivalent spaceless path for each file. (How??)

There has to be an easier way than all this, doesn't there? Does anyone know?

(Actually, I would quite like to be able to concatenate rtf files without having to convert them to text files beforehand. Does anyone know how to do this?



ScottTheSculptor
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 27 Dec 2011
Gender: Male
Posts: 47

30 May 2012, 5:12 pm

skysaw wrote:
But ... but ... the command prompt does not recognise filenames with spaces in.


quote the filename

then the space will be recognized


_________________
There are no absolute truths, only well established ones.
"Truth" is the best logic that fits the available evidence.
Logic is derived from the structure and iterative nature of the universe.
Gather evidence, apply logic, argue until agreement and that defines the "truth", for now.
If you don't agree, gather more evidence, strengthen your logical arguments.
This is the first tenet of the House of Logic.


mcg
Veteran
Veteran

User avatar

Joined: 26 Jan 2010
Age: 34
Gender: Male
Posts: 538
Location: Sacramento

31 May 2012, 4:55 pm

This should do it:

Code:
for /F %f in ('dir /b *.txt ^| sort') do type %f >> bigFile.txt