Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Long
End Type
Private Const MAX_PATH As Long = 260
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
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
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 FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
' My data structure, as opposed to API call structures
Private Type FileType
Group As Long
Folder As String
FileName As String
FileDate As Date
FileSize As Currency
Flags As Long
End Type
Private Sub AddFolder(ByVal pstrFolder As String)
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Dim strPath As String
Dim strFile As String
Dim lngHandle As Long
Dim intSearching As Integer
Dim typFile As FileType
Dim typFind As WIN32_FIND_DATA
intSearching = 1
lngHandle = FindFirstFile(pstrFolder & "\*.*", typFind)
Do While lngHandle <> INVALID_HANDLE_VALUE And intSearching <> 0
strFile = Left$(typFind.cFileName, InStr(typFind.cFileName, vbNullChar) - 1)
If (typFind.dwFileAttributes And vbDirectory) = vbDirectory Then
If Left$(strFile, 1) <> "." Then AddFolder pstrFolder & "\" & strFile
Else
Select Case strFile
Case "desktop.ini"
Case Else
With typFile
.Group = mlngGroup
.Folder = Mid$(pstrFolder, Len(mstrPrefix) + 1)
.FileName = strFile
.FileDate = StructureToDate(typFind.ftLastWriteTime)
.FileSize = CCur((typFind.nFileSizeHigh * MAXDWORD) + typFind.nFileSizeLow)
End With
AddFile typFile
End Select
End If
intSearching = FindNextFile(lngHandle, typFind)
Loop
lngHandle = FindClose(lngHandle)
End Sub
Private Function StructureToDate(ptyp As FILETIME) As Date
Dim typLocal As FILETIME
Dim typSystem As SYSTEMTIME
If FileTimeToLocalFileTime(ptyp, typLocal) = 1 Then
If FileTimeToSystemTime(typLocal, typSystem) = 1 Then
With typSystem
StructureToDate = DateSerial(.wYear, .wMonth, .wDay) + TimeSerial(.wHour, .wMinute, .wSecond)
End With
End If
End If
End Function
' This is the actual function I use, which includes references and data structures not included in this post
Private Sub AddFile(ptypFile As FileType, plngSource As Long)
Dim lngMax As Long
Dim i As Long
With mtypDrive(plngSource)
.Current = .Current + 1
If .Current > .Files Then
.Files = (.Files * 5) \ 4
ReDim Preserve .File(1 To .Files)
End If
.File(.Current) = ptypFile
End With
End Sub