Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
CONCATENATE TEXT FILES USING FSO A program to con...
Author:
Louis Delongchamp
E-mail:
Click to e-mail author
Website:
http://www.cyberbeach.net/~loudelon
Submitted:
8/2/2001
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
17211
CONCATENATE TEXT FILES USING FSO A program to concatenate all the .txt files of the current directory into a BIG file called BigText
Declarations:
Make sure that the directory you are working in has files of type .txt, that there are not too many of them and that they are not too big! Do not forget at the end to erase BigText from your hard drive. Start a new VB6 project and place this code in the form.
Code:
Option Explicit Private Sub Form_Load() Concatenate End End Sub Private Sub Concatenate() Dim WkDir As String, S As String Dim fsO As Object Dim fsF As Object Dim fsN As Object Dim fsT As Object Dim fsW As Object ' Prepare a message for the end S = "Concatenation of the text files:" & vbCr ' Start FSO Set fsO = CreateObject("Scripting.FileSystemObject") ' Retrieve our current location on the hard drive WkDir = App.Path ' Create BigText, the file that will contain the concatenation. Set fsW = fsO.opentextfile(WkDir & "\BigText", 2, True) ' Get the names of all the files in the WkDir Set fsF = fsO.GetFolder(WkDir).Files ' Process each file For Each fsN In fsF ' Choose the ones ending in .txt If Right(fsN.Name, 3) = "txt" Then ' Add the name of the file to our Message for the end S = S & fsN.Name & vbCr ' Open the file Set fsT = fsO.opentextfile(WkDir & "\" & fsN.Name, 1) ' Write a line that contains the file name to seperate each file in BigText fsW.writeline ("") fsW.writeline ("############### New file " & fsN.Name & " ###############") fsW.writeline ("") ' Insert into BigText each line of the .txt file Do While Not fsT.atendofstream fsW.writeline (fsT.readline) Loop ' Close the .txt file fsT.Close End If Next fsN ' Close BigText fsW.Close MsgBox S, , "The File BigText" Set fsO = Nothing Set fsF = Nothing Set fsN = Nothing Set fsT = Nothing Set fsW = Nothing End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement