-
December 28th, 2011, 04:50 PM
#1
Copy over 4GB files with progress problem.
So far i have made some routines that copy files over 2gb but corrupted, add some extra bytes at the end and can't copy files bigger than 4GB if you can help me will appreciate it because can't find solution for long time
I realy need a working copy function for files over 4GB please help me
TotalFileSize = fso.GetFile(SourceFile).Size
'Open file
Dim sFile As Long
Dim dFile As Long
sFile = CreateFile(SourceFile, GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0, 0)
dFile = CreateFile(Destination, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, CREATE_NEW, 0, 0)
Dim Buffer$
Dim bytesWritten As Long
If sFile <> INVALID_HANDLE_VALUE Then
'move file pointer
SetFilePointer sFile, 0, ByVal 0, FILE_BEGIN
Do
'check if user cancel copy
If mvariCancel Then
GoTo CLoseFiles
End If
CurPos = SetFilePointer(sFile, 0, ByVal 0, FILE_CURRENT)
If Left(CStr(CurPos), 1) = "-" Then
CurPos = TotalFileSize - Abs(CurPos)
If Form1.Text3 = "" Then Form1.Text3 = CurPos
End If
CurPosOn = CurPos / 100
Totalto = TotalFileSize / 100
mvarPercentREady = (CurPosOn * 100) / Totalto
Debug.Print CurPos, CurPosOn, Totalto, mvarPercentREady
DoEvents
If TotalFileSize - CurPos < ReadChunkSize& Then
ReadChunkSize& = TotalFileSize - CurPos ' get to the end of the file
BufferSize& = ReadChunkSize& * 2
End If
r$ = String$(ReadChunkSize&, Chr$(0))
retval = ReadFileNO(sFile, ByVal r$, Len(r$), iEOF, 0)
Buffer$ = Buffer$ + r$
If Len(Buffer$) >= BufferSize& Then
WriteFile dFile, ByVal Buffer$, Len(Buffer$), bytesWritten, ByVal 0&
Buffer$ = ""
End If
Loop Until iEOF = 0
End If
CLoseFiles:
CloseHandle sFile
CloseHandle dFile
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|