'(c)2001, 2004 by Louis. Functions for FAST (!) file access.
'GFFileAccess_GetDirFileSizeTotal
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
'Get[Total/Avail]DiskSpace (source: drvspace.zip)
Private Declare Function GetDiskFreeSpace Lib "kernel32.dll" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpClusterSectorNumber As Long, lpSectorByteNumber As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, lpFreeBytesAvailableToCaller As ULARGE_INTEGER, lpTotalNumberOfBytes As ULARGE_INTEGER, lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'GFFileAccess_GetDirFileSizeTotal
Private Const MAX_PATH = 260
'GFFileAccess_GetDirFileSizeTotal
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
'GFFileAccess_GetDirFileSizeTotal
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
'GFFileAccess_Get[Free/Total]DiskSpace
Private Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Public Function GFFileAccess_GetDirFileSizeTotal(ByVal DirectoryName As String, ByVal Pattern As String) As Double
'on error resume next 'returns total file size of all files matching the passed search pattern or -1 for error
Dim FindFileHandle As Long
Dim FileSizeTotal As Double
Dim WIN32_FIND_DATAVar As WIN32_FIND_DATA
'
'NOTE: this function is bloody fast, in tests it needed less that 2 seconds
'on an Athlon 800 to get the total size of 31.461 mp3 files.
'
'verify
If Dir(DirectoryName, vbDirectory) = "" Then
GFFileAccess_GetDirFileSizeTotal = (-1#) 'error
Exit Function
End If
If Not (Right$(DirectoryName, 1) = "\") Then DirectoryName = DirectoryName + "\"