Как получить длинну файла, если размер файла более 4гб ?
FileLen() возвращает отрицательное значение:(. Длинна файла больше диапазона Long... Заранее огромное спасибо!
Public Function FileSize(FilePath As String) As Double
Dim lpFSHigh As Long 'старший разряд
Dim lpFSLow As Long 'младший
Dim h32 As Double
Dim WFD As WIN32_FIND_DATA
Dim hFile&
On Error Resume Next
Err.Clear
h32 = 2 ^ 32
hFile = FindFirstFile(FilePath, WFD)
If hFile = INVALID_HANDLE_VALUE Then Exit Function
lpFSLow = WFD.nFileSizeLow
lpFSHigh = WFD.nFileSizeHigh
If lpFSLow >= 0 Then
FileSize = lpFSLow
Else
FileSize = h32 + lpFSLow
End If
FileSize = FileSize + h32 * lpFSHigh
FindClose hFile
Err.Clear
End Function
alibek писал(а):А что не мелочи?
Private Const INVALID_HANDLE_VALUE = -1
Private Const OPEN_EXISTING = 3
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GethFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile As Long, lpFileSizeHigh As Any) As Long
Private Declare Sub PutMem4 Lib "msvbvm60" (Destination As Any, ByVal Value As Long)
Private Function GetFileSize(FileName As String) As Currency
Dim hFile As Long
hFile = CreateFile(FileName, 0, 0, ByVal 0&, OPEN_EXISTING, 0, 0)
If Not (hFile = INVALID_HANDLE_VALUE) Then
PutMem4 GetFileSize, GethFileSize(hFile, ByVal VarPtr(GetFileSize) + 4)
GetFileSize = GetFileSize * &H2710
CloseHandle hFile
End If
End Function
Сейчас этот форум просматривают: SemrushBot и гости: 98