Private Function SearchForFiles(FP As FILE_PARAMS) As Double
'local working variables
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
Dim nSize As Long
Dim sPath As String
Dim sRoot As String
Dim sTmp As String
sRoot = QualifyPath(FP.sFileRoot)
sPath = sRoot & "*.*"
'obtain handle to the first match
hFile = FindFirstFile(sPath, WFD)
'if valid ...
If hFile <> INVALID_HANDLE_VALUE Then
'This is where the method obtains the file
'list and data for the folder passed.
'
'GetFileInformation function returns the size,
'in bytes, of the files found matching the
'filespec in the passed folder, so it is
'assigned to nSize. It is not directly assigned
'to FP.nFileSize because nSize is incremented
'below if a recursive search was specified.
nSize = GetFileInformation(FP)
FP.nFileSize = nSize
Do
'if the returned item is a folder...
If (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
'..and the Recurse flag was specified
If FP.bRecurse Then
'remove trailing nulls
sTmp = TrimNull(WFD.cFileName)
'and if the folder is not the default
'self and parent folders...
If sTmp <> "." And sTmp <> ".." Then
'..then the item is a real folder, which
'may contain other sub folders, so assign
'the new folder name to FP.sFileRoot and
'recursively call this function again with
'the ammended information.
'
'Since nSize is a local variable, whose value
'is both set above as well as returned as the
'function call value, the nSize needs to be
'added to previous calls in order to maintain accuracy.
'
'However, because the nFileSize member of
'FILE_PARAMS is passed back and forth through
'the calls, nSize is simply assigned to it
'after the recursive call finishes.
FP.sFileRoot = sRoot & sTmp
nSize = nSize + SearchForFiles(FP)
FP.nFileSize = nSize
End If
End If
End If
'continue looping until FindNextFile returns
'0 (no more matches)
Loop While FindNextFile(hFile, WFD)
'close the find handle
hFile = FindClose(hFile)
End If
'because this routine is recursive, return
'the size of matching files
SearchForFiles = nSize
End Function