by Ekapop Tec. (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 16th August 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Merging/concatenating the serveral source files name to one target file name
API Declarations
' In case some problems occure, you can contact me at [email protected]
' MODULE............: MERGING FILE NAME
' OBJECTIVE.........: To merge the serveral source files name to a target file
' AUTHOR............: EKAPOP TECHAWANTO
' COMPANY NAME......: Advanced Systems Consulting Co., Ltd. (THAILAND)
' CREATED DATE......: 16 August 2004
' -----------------------------------------------------------------------------
' AMENDMENTION WHO DATE OBJECTIVE
'
' -----------------------------------------------------------------------------
' NOTE.........................: If you change anything in methods, properties or patterns,
' should note that one above the method, properties or note session.
' Parameter Input:
' vaFromFileName is an array of the source file
' sTargetFileName is a target/destination file name
' sTargetExtensionName is an extension name of the target file name
'
Public Function Merging_FileName(vaFromFileName As Variant, _
ByVal sTargetFileName As String, _
ByVal bWritingNotAppend As Boolean, _
Optional ByVal sTargetExtensionName As String = ".txt") As Boolean
On Error GoTo Error_Handle
Dim oFSO As FileSystemObject
Dim oFile As TextStream
Dim oFileTarget As TextStream
Dim iMode As IOMode
Dim sModule As String
Dim iIndex As Integer
Dim iMax As Integer
Dim bFileOpen As Boolean
Dim bTargetOpen As Boolean
Dim bRet As Boolean
sModule = "MERGFIL"
' Make sure the parameter has assigned
If IsEmpty(vaFromFileName) Then
GoTo Clear_Resource
End If
' Make sure the parameter as an array type
If Not IsArray(vaFromFileName) Then
GoTo Clear_Resource
End If
'
sTargetFileName = Trim$(sTargetFileName)
If Len(Trim$(sTargetFileName)) < 1 Then
GoTo Clear_Resource
End If
'
' Create object
Set oFSO = New FileSystemObject
'/********************/
'// Set the Target File Name
' Set I/O Operation mode
If bWritingNotAppend Then
' Writing Status
iMode = ForWriting
Else
iMode = ForAppending
End If
'
If InStr(1, sTargetFileName, ".", vbTextCompare) < 1 Then
sTargetFileName = sTargetFileName & sTargetExtensionName
ElseIf Right$(sTargetFileName, 1) = "." Then
sTargetFileName = Left$(sTargetFileName, Len(sTargetFileName) - 1) & sTargetExtensionName
End If
'/********************/
'
' Set a target/destination file name active, and the openning file name status
Set oFileTarget = oFSO.OpenTextFile(sTargetFileName, iMode, True)
bTargetOpen = True
'
' Get the maximum of the boundary array
iMax = UBound(vaFromFileName)
For iIndex = 0 To iMax
DoEvents
' Check file name not null string
If Len(Trim$(vaFromFileName(iIndex))) > 0 Then
' Check File Name Exists in directory
If Len(Dir$(vaFromFileName(iIndex))) > 0 Then
Set oFile = oFSO.OpenTextFile(vaFromFileName(iIndex), ForReading)
bFileOpen = True
' Read data as a Streamming style
While Not oFile.AtEndOfStream
' Read all data contains in the file
oFileTarget.Write oFile.ReadAll
Wend
oFile.Close
bFileOpen = False
End If
End If ' Check File Not Empty String
Next iIndex
' Prepare to close a target file name
If bTargetOpen Then
oFileTarget.Close
bTargetOpen = False
bRet = True
End If
GoTo Clear_Resource
'*** Error ***
Error_Handle:
loc_sErrMsg = "MERGINGFN::" & Err.Description
Clear_Resource:
If Not oFile Is Nothing Then
If bFileOpen Then
oFile.Close
End If
Set oFile = Nothing
End If
'
If Not oFileTarget Is Nothing Then
If bTargetOpen Then
oFileTarget.Close
End If
Set oFileTarget = Nothing
End If
'
If Not oFSO Is Nothing Then
Set oFSO = Nothing
End If
Merging_FileName = bRet
End Function
No comments have been posted about Merging/concatenating the serveral source files name to one target file name. Why not be the first to post a comment about Merging/concatenating the serveral source files name to one target file name.