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
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
I have not tried this personally but a simple binary access routine should work just fine on any file size supported by the OS/File System.
Basically something like this.
Open the file source file for binary read
Open Target file for Binary write
Do ' until eof
Get chunk from source
Put chunk to target
loop
close files
You should also be able to call a windows API function to copy a file with the windows progress dialog shown as well.
i have try that already but geting error on Loc(infil) with big files
infil = FreeFile
Open SourceFile For Binary Access Read Lock Write As #infil
outfil = FreeFile '
Open Destination For Binary Access Write Lock Write As #outfil
Both Lof and Loc result in a long which has a max value of 2,147,483,647. You would get an error if you try to use one of these functions on a file containing more bytes that this var can hold.
Bookmarks