• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Combine text files to a single file

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
bt707
Asked:
bt707
  • 5
  • 4
  • 4
1 Solution
 
vinnyd79Commented:
Have you tried using copy?

cd c:\logfiles
ren *.* *.txt
copy *.txt Newfile.txt
0
 
vinnyd79Commented:
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
 
ashooooCommented:
You can also type this on the command line

type *.txt > new.txt
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
vinnyd79Commented:
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
 
bt707Author Commented:
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
 
ashooooCommented:
Whats the error?
0
 
vinnyd79Commented:
Did you add a Filelistbox called File1?
0
 
bt707Author Commented:
run-time error 424
object required
0
 
bt707Author Commented:
no i did not add a filelistbox called File1, not even sure how to do that.

Thanks,
0
 
vinnyd79Commented:
Just add a Filelistbox to your form.It should be in your vb toolbox on the left.It looks like a document icon.
0
 
ashooooCommented:
On the components tab, there is a control called FileListBox, just add it to your form and name it File1.
0
 
ashooooCommented:
You might also want to keep this control invisible at runtime. Depends on your requirements.
0
 
bt707Author Commented:
ok I think i can get it from here, thanks for all the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 5
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now