Solved

Combine text files to a single file

Posted on 2003-10-28
13
279 Views
Last Modified: 2010-05-03
I have a lot of log files in a folder and would like to be able to rename the (.log) to (.txt) and
then combine all of them into one txt file.

I can use the dos command CD c:\logfiles ren *.* *.txt     to rename the all the ext's but how can i run a script that will combine all the files into one.

Thanks,
0
Comment
Question by:bt707
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
13 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9634465
Have you tried using copy?

cd c:\logfiles
ren *.* *.txt
copy *.txt Newfile.txt
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9634532
You can call it through vb using Shell:

Private Sub Command1_Click()
ChDrive "C:\"
ChDir "C:\logfiles"
Shell Environ("Comspec") & " /c copy *.* C:\NewFile.txt", vbHide
End Sub
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9634576
You can also type this on the command line

type *.txt > new.txt
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
ID: 9634630
You could also add a filelistbox and loop through it adding the contents of each file into a new file:

Private Sub Form_Load()
File1.Path = "C:\logfiles"
End Sub

Private Sub Command1_Click()
Dim tFile As String, NewFile As String, Ln As String
Dim ff As Integer, nf As Integer, i As Integer

NewFile = "C:\Newfile.txt"

nf = FreeFile
Open NewFile For Output As #nf

For i = 0 To File1.ListCount - 1
tFile = File1.Path & "\" & File1.List(i)
ff = FreeFile
Open tFile For Input As #ff
Do Until EOF(ff)
Line Input #ff, Ln
Print #nf, Ln
Loop
Close #ff
Next i

Close #nf

End Sub
0
 

Author Comment

by:bt707
ID: 9634707
I'm getting a error, when i click on debug it is telling me that the error is in this line

File1.Path = "C:\logfiles"

the files are in this folder, not sure what's going on.

Thanks,
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9634726
Whats the error?
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9634739
Did you add a Filelistbox called File1?
0
 

Author Comment

by:bt707
ID: 9634740
run-time error 424
object required
0
 

Author Comment

by:bt707
ID: 9634747
no i did not add a filelistbox called File1, not even sure how to do that.

Thanks,
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9634766
Just add a Filelistbox to your form.It should be in your vb toolbox on the left.It looks like a document icon.
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9634783
On the components tab, there is a control called FileListBox, just add it to your form and name it File1.
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9634805
You might also want to keep this control invisible at runtime. Depends on your requirements.
0
 

Author Comment

by:bt707
ID: 9634837
ok I think i can get it from here, thanks for all the help.
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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