Computing.Net > Forums > Programming > Bat Prog: Copy 1 txt files into 1?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Bat Prog: Copy 1 txt files into 1?

Reply to Message Icon

Name: Zephyrus14
Date: March 22, 2009 at 13:10:54 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: March 22, 2009 at 13:42:41 Pacific
Reply:


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


0

Response Number 2
Name: Zephyrus14
Date: March 22, 2009 at 14:03:57 Pacific
Reply:

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?


0

Response Number 3
Name: IVO
Date: March 22, 2009 at 14:21:00 Pacific
Reply:


@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.


0

Response Number 4
Name: Zephyrus14
Date: March 22, 2009 at 15:24:04 Pacific
Reply:

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?


0

Response Number 5
Name: IVO
Date: March 22, 2009 at 15:45:36 Pacific
Reply:


@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.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Bat Prog: Copy 1 txt files into 1?

Simple Batch File www.computing.net/answers/programming/simple-batch-file/19877.html

Win2k batch: copy only new files? www.computing.net/answers/programming/win2k-batch-copy-only-new-files/10386.html

Move 1.txt file to other folder and www.computing.net/answers/programming/move-1txt-file-to-other-folder-and/16588.html