Lösung - Dateien grösser als 2GB lesen/schreiben
Hallo Rainer,
habe Deinen Tipp verstanden, aber Dateien mit „Microsoft Scripting
Runtime“ zu kopieren ist nicht so mein Ding.
Mittlerweile habe ich mir eine Lösung erarbeitet.
Nachdem die Dateigrösse bekannt ist (curFileSize) und die Anzahl der
Bytes die pro Loop gelesen bzw. geschrieben werden (lngCurBufSize) ist
es jetzt leicht sich den Prozent-Wert vom Kopiervorgang auszurechnen
- diesen Teil habe ich hier aber ausgelassen. Wenn man möchte, kann
man auch noch eine Abbruch-Bedingung einbauen.
Habe es bereits mit einer 10GB Datei getestet!!
greets from michL
Private Declare Function GetFileSizeEx Lib "kernel32" (ByVal hFile As Long, lpFileSize As Currency) As Boolean
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFilename As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function FlushFileBuffers Lib "kernel32" (ByVal hFile As Long) As Long
'
Private Const GENERIC\_WRITE = &H40000000
Private Const GENERIC\_READ = &H80000000
Private Const FILE\_ATTRIBUTE\_NORMAL = &H80
Private Const OPEN\_EXISTING = 3
Private Const CREATE\_NEW = 1
Private Const INVALID\_HANDLE\_VALUE = -1
'
Private Sub Test()
'
Dim fReadHandle As Long
Dim fWriteHandle As Long
Dim curFileSize As Currency
Dim fSuccess As Long
Dim lBytesRead As Long
Dim lBytesWritten As Long
Dim ReadBuffer() As Byte
Dim lngCurBufSize As Long
Dim src As String
Dim dst As String
'
src = "c:\temp\quelle.txt"
dst = "c:\temp\ziel.txt"
'
fReadHandle = CreateFile(src, GENERIC\_READ, 0, 0, OPEN\_EXISTING, FILE\_ATTRIBUTE\_NORMAL, 0)
'
fSuccess = GetFileSizeEx(fReadHandle, curFileSize)
curFileSize = curFileSize \* 10000
'
fWriteHandle = CreateFile(dst, GENERIC\_WRITE, 0, 0, CREATE\_NEW, FILE\_ATTRIBUTE\_NORMAL, 0)
'
lngCurBufSize = 500000
ReDim ReadBuffer(0 To lngCurBufSize)
'
fSuccess = ReadFile(fReadHandle, ReadBuffer(0), lngCurBufSize, lBytesRead, 0)
'
Do While lBytesRead \> 0
fSuccess = WriteFile(fWriteHandle, ReadBuffer(0), lBytesRead, lBytesWritten, 0)
fSuccess = FlushFileBuffers(fWriteHandle)
fSuccess = ReadFile(fReadHandle, ReadBuffer(0), lngCurBufSize, lBytesRead, 0)
Loop
fSuccess = CloseHandle(fReadHandle)
fSuccess = CloseHandle(fWriteHandle)
'
End Sub