' 撰寫人:Devil(璉璉) E-Mail: qvb3377@ms5.hinet.net 僅供學術測試使用,引用請註明原出處 ' -------------------------------------------------------------------------------------- Public Function myFileCopy(ByVal strSource As String, ByVal strTarget As String, Optional ByVal nByte As Long = 32768, Optional ByVal bResume As Boolean = False, Optional GetSize, Optional nFileSize, Optional bStop) ' nByte 每次複製 32 k , 小於 64 k 可以避免跨節區 Dim SourceFile As New cApiFile, TargetFile As New cApiFile Dim tBytes() As Byte mErrorCode = 0 With SourceFile .OpenFile strSource, ReadOnly nFileSize = .FileSize End With hSeekPointer = 1 If Dir(strTarget) <> "" Then If bResume Then With TargetFile .OpenFile strTarget hSeekPointer = .FileSize + 1 .CloseFile End With Else Kill strTarget End If End If With SourceFile .SeekAbsolute hSeekPointer End With With TargetFile .OpenFile strTarget, WriteOnly .SeekAbsolute hSeekPointer End With With SourceFile For i = hSeekPointer To nFileSize Step nByte If i + nByte >= nFileSize Then ReadBytes = .ReadBytes(nFileSize - i + 1) If IsArray(ReadBytes) Then tBytes = ReadBytes TargetFile.WriteBytes tBytes nGetSize = nFileSize Else mErrorCode = ReadBytes Exit For End If Else ReadBytes = .ReadBytes(nByte) If IsArray(ReadBytes) Then tBytes = ReadBytes TargetFile.WriteBytes tBytes() nGetSize = i Else mErrorCode = ReadBytes Exit For End If End If If Not IsMissing(bStop) Then If bStop Then Exit For End If End If DoEvents Next .CloseFile TargetFile.CloseFile End With myFileCopy = mErrorCode End Function