ecommerce web developer development freelance website designer India
You can use the CFileCopy class to monitor file copy progress, and even concatenate files into a single
destination. There's little difference between copying a single file and concatenating two or more to a single
destination. You simply keep the destination file open, while repeatedly opening, reading, and writing source files.

Public Function ConcatFiles(ByVal Destination _
As String, ParamArray Source()) As Boolean
Dim hSource As Long
Dim hDest As Long
Dim Src As Variant

' Handle special cases of 0 or 1 file(s)
Select Case UBound(Source)
Case -1
' No files passed, this would be a
' problem
Exit Function
Case 0
' Single file
ConcatFiles = Me.CopyFile(Source(0), _
Destination)
Exit Function
End Select

' Check destination - use first source
' filename if none given
If IsDirectory(Destination) Then
Destination = Destination & _
IIf(Right(Destination, 1) = "\", "", _
"\") & ExtractName(Source(0))
End If

' Get rid of existing file
If IsFile(Destination) Then
If KillFile(Destination) = False Then
' Error: Can't kill destination
Exit Function
End If
End If

' Initialize tracking variables
Src = Source
m_BytesToCopy = SumBytes(Src)
m_BytesCopied = 0
m_FilesToCopy = UBound(Source) + 1
m_FilesCopied = 0
m_Cancel = False

' Enable error trap
On Error GoTo CopyFailed

' Open Destination
hDest = FreeFile
Open Destination For Binary Access Write As _
#hDest

For Each Src In Source
' Check source
If IsFile(Src) Then
' Open this source
hSource = FreeFile
Open Src For Binary Access Read As _
#hSource
' Sling bits and close source
Call CopyBits(hSource, hDest)
Close #hSource
End If
Next Src

' Clean up
Close #hDest

' Delete partial file if user cancelled
If m_Cancel Then KillFile Destination

' If we made it here, we probably succeeded!
ConcatFiles = (m_Cancel = False)
Exit Function

CopyFailed:
' Error: Should be recorded and reported
End Function

Private Function CopyBits(ByVal hSource As _
Long, ByVal hDest As Long) As Boolean
Dim nSize As Long, Buffer() As Byte
Dim nCopied As Long, i As Long
Const BuffSize As Long = 32 * 1024&

' Need filesize for some calcs
nSize = LOF(hSource)

' Loop through one buffer at a time
If nSize >= BuffSize Then
ReDim Buffer(1 To BuffSize) As Byte
For i = 1 To (nSize \ BuffSize)
Get #hSource, , Buffer
Put #hDest, , Buffer
Call UpdateProgress(BuffSize)
If m_Cancel Then Exit For
Next i
End If

' Get last chunk of file
If m_Cancel = False Then
If nSize Mod BuffSize Then
ReDim Buffer(1 To (nSize Mod _
BuffSize)) As Byte
Get #hSource, , Buffer
Put #hDest, , Buffer
Call UpdateProgress(UBound(Buffer))
End If
End If

' Increment counter
If m_Cancel = False Then
m_FilesCopied = m_FilesCopied + 1
End If
End Function

Private Sub UpdateProgress(ByVal nCopied As Long)
' Let client know about progress
m_BytesCopied = m_BytesCopied + nCopied
RaiseEvent ProgressUpdate((m_BytesCopied / _
m_BytesToCopy) * 100)
End Sub
Concatenate Files With Manual Copy

901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

Express News India | Freelance ecommerce web development India