?
Solved

Copy the content of several text files into one file

Posted on 2011-04-28
2
Medium Priority
?
412 Views
Last Modified: 2012-05-11
Hi Experts,

I have created a text file containing the full path to several text files.

Sample from file called copylist.txt:

C:\test\ifdata.txt
C:\test2\ifdata.txt
C:\test3\ifdata.txt
C:\test46\ifdata.txt
C:\test45\ifdata.txt
C:\test48\ifdata.txt
C:\test64\ifdata.txt

As you can see, all files have the same name, but are located in different folders, and have different content.

What I need to do is to copy the content of all these files into one large text file.

Ideas?

Thanks,
Bjorn
0
Comment
Question by:intimenordic
2 Comments
 
LVL 86

Accepted Solution

by:
oBdA earned 2000 total points
ID: 35482148
There are at least two methods you can try:
@echo off
setlocal enabledelayedexpansion
set CombinedFile=ifdata-combined.txt
set cl=
for /f "delims=" %%a in ('type "copylist.txt"') do (
  set cl=!cl!+"%%~a"
)
set cl=%cl:~1%
copy /a !cl! "%CombinedFile%"

Open in new window

@echo off
setlocal
set CombinedFile=ifdata-combined.txt
if exist "%CombinedFile%" del "%CombinedFile%"
for /f "delims=" %%a in ('type "copylist.txt"') do (
  type "%%~a" >>"%CombinedFile%"
)

Open in new window

0
 

Author Closing Comment

by:intimenordic
ID: 35482219
Perfect! Thanks a lot.

Regards,
Bjorn
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question