colore

combine multiple text files in one

11 posts in this topic

hello

I need to combine multiple text files in one

I mean to stitch them one after the other

is there a program that can do this?

I used TXT Collector and Text Magician but none did it (there are 100,000 txt files)

thanks

0

Share this post


Link to post
Share on other sites

you should be able to use the straight copy command, I would think.

copy *.txt mytextfile.txt

Or some such thing. You would have to load the result file up and make formatting changes, etc, but hopefully it should work out for you.

0

Share this post


Link to post
Share on other sites
copy *.txt mytextfile.txt

thanks! this works!

EDIT:

mmm there is a problem

the files are sorted per filename in the explorer and this is the sequence in which I want to combine them:

1.txt

10.txt

20.txt

etc

but the above command combines them in this order:

1.txt

10.txt

100.txt

etc

any idea?

Edited by colore
0

Share this post


Link to post
Share on other sites

may be you can try this.. little longer but it will work for you.

copy ?.txt 01.tmp
copy ??.txt 02.tmp
copy ???.txt 03.tmp
...

like this... this will get all 0.txt - 9.txt in 01.tmp, then 10.txt-99.txt in 02.tmp and so on. once you are done this, then get all tmp files merged.

copy *.tmp final.txt

A bit lengthy, but it will do the job.

0

Share this post


Link to post
Share on other sites

unfortunately it doesn't the job

for example this:

copy ??.txt 02.tmp

combines these:

1.txt

10.txt

100.txt

110.txt

120.txt

130.txt

140.txt

150.txt

160.txt

170.txt

180.txt

190.txt

20.txt

200.txt

210.txt

220.txt

230.txt

240.txt

250.txt

260.txt

270.txt

280.txt

290.txt

30.txt

300.txt

310.txt

320.txt

330.txt

340.txt

350.txt

360.txt

370.txt

380.txt

390.txt

40.txt

400.txt

410.txt

420.txt

430.txt

440.txt

450.txt

460.txt

470.txt

480.txt

490.txt

50.txt

500.txt

510.txt

520.txt

530.txt

540.txt

550.txt

560.txt

570.txt

580.txt

590.txt

60.txt

600.txt

610.txt

620.txt

630.txt

640.txt

650.txt

660.txt

670.txt

680.txt

690.txt

70.txt

700.txt

710.txt

720.txt

730.txt

740.txt

750.txt

760.txt

770.txt

780.txt

790.txt

80.txt

800.txt

810.txt

820.txt

830.txt

840.txt

850.txt

860.txt

870.txt

880.txt

890.txt

90.txt

900.txt

910.txt

920.txt

930.txt

940.txt

950.txt

960.txt

970.txt

980.txt

990.txt

0

Share this post


Link to post
Share on other sites

what I suppose would do the job is to put zeros in front of the filenames

but is there any program that will put zeros in front of the filenames, but make all the filenames have the same number of digits?

I mean, it must not just add 3 zeros in front of all filenames, it should add

3 zeros infront of ?.txt filenames

2 zeros in front of ??.txt filenames

1 zero in front of ???.txt filenames

etc

example:

I have:

2150

61250478

122

and need:

00002150

61250478

00000122

Edited by colore
0

Share this post


Link to post
Share on other sites

how's this, will pad the file name with zero's in front to end up with an 8 character filename.

@echo off
setlocal enableextensions
setlocal enabledelayedexpansion

for %%? in (*.txt) do (
set fname=%%?
set fname=!fname:~0,-4!
set nname=
for /l %%z in (7,-1,0) do (
if "!fname:~%%z!"=="" (
set nname=0!nname!
)
)
ren "%%?" "!nname!%%?"
)

0

Share this post


Link to post
Share on other sites
unfortunately it doesn't the job

for example this:

copy ??.txt 02.tmp

combines these:

1.txt

10.txt

100.txt

...

i don't think ??.txt will match with 100.txt

? represents 0 or 1 charactor. so it will be max 2 digit file name, not 3 digit.

but in your case, ??.txt will match both 1.txt and 10.txt.

may be you can move files which you have merged to some other folder using move command.

copy ?.txt 01.tmp
md 1
move ?.txt 1

copy ??.txt 02.tmp
md 2
move ?.txt 2

copy ???.txt 03.tmp
md 3
move ?.txt 3

0

Share this post


Link to post
Share on other sites
how's this, will pad the file name with zero's in front to end up with an 8 character filename.

@echo off
setlocal enableextensions
setlocal enabledelayedexpansion

for %%? in (*.txt) do (
set fname=%%?
set fname=!fname:~0,-4!
set nname=
for /l %%z in (7,-1,0) do (
if "!fname:~%%z!"=="" (
set nname=0!nname!
)
)
ren "%%?" "!nname!%%?"
)

thanks

but how do I use this?

aadipa, indeed, I wanted to write ???.txt, sorry

0

Share this post


Link to post
Share on other sites

save it as pad_zeros.cmd in the folder with your files. the double click

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.