Bat Prog: Copy 1 txt files into 1?

March 22, 2009 at 13:10:54
Specs: Windows XP
Hello,

I have a directory, lets call it "C:\Folder". Inside this directory are multiple text files. There could be only 1, but there could be 30 of them, it all depends. These text files are also named different things every time. All I need to do is to copy the contents of each text file into one large text file (lets call it output.txt). I'm completely lost :(. Anyone, please help! Thanks!


See More: Bat Prog: Copy 1 txt files into 1?

Report •


#1
March 22, 2009 at 13:42:41

@echo off
pushd C:\Folder
for %%j in (*.txt) do type "%%j" >> output.txt
popd
:: End_Of_Batch


Report •

#2
March 22, 2009 at 14:03:57
This works great! Thanks!

But... I need a line break in between each of the entries from the multiple text files in output.txt.

any way to do that too?


Report •

#3
March 22, 2009 at 14:21:00

@echo off
pushd C:\Folder
for %%j in (*.txt) do (
echo.>> output.txt
type "%%j" >> output.new
)
ren output.new output.txt
popd
:: End_Of_Batch

Beware output.txt must not be in the same folder of the source text files.

Report •

Related Solutions

#4
March 22, 2009 at 15:24:04
IVO,

I've copied and pasted the code you have provided, but this leaves me with an output.txt with four lines with 1 space on each line (four lines because I had 4 txt files in the folder, as a test). So, in other words, it creates the line breakes, but looses the data.

I really appreciate your help, but am I doing something wrong?


Report •

#5
March 22, 2009 at 15:45:36

@echo off
pushd C:\Folder
for %%j in (*.txt) do (
echo.>> output.new
type "%%j" >> output.new
)
ren output.new output.txt
popd
:: End_Of_Batch

Sorry I made a tiny mistake correcting the code as , I repeat, output.txt can't be generated directly into the folder, so I name it .new then rename to .txt when the process ends.

Report •


Ask Question