
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 GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Dim iDir As String
Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
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 Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function
Private Function FindFilesAPI2(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer, sFound() As String, Optional oldpath As String)
On Error Resume Next
'KPD-Team 1999
'Улучшения (c) hCORe 2004
'E-Mail: KPDTeam@Allapi.net
' vb6@mail.ru
'URL: http://www.allapi.net/
' http://amelso.narod.ru
Dim FileName As String ' Переменная для имени...
Dim DirName As String ' Папка
Dim dirNames() As String ' Буфер папок
Dim nDir As Integer ' количество директорий
Dim i As Integer ' счетчик цикла...
Dim hSearch As Long ' дескриптор поиска
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(path, 1) <> "\" Then path = path & "\"
' Поиск подпапок.
nDir = 0
ReDim dirNames(nDir)
Cont = True
' Пройти по всем папкам и
' просуммировать размеры файлов.
hSearch = FindFirstFile(path & SearchStr, WFD)
Cont = True
ReDim sFound(0) as String
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
DoEvents
FileName = StripNulls(WFD.cFileName)
If (FileName <> ".") And (FileName <> "..") Then
FindFilesAPI2 = FindFilesAPI2 + (WFD.nFileSizeHigh _
* MAXDWORD) + WFD.nFileSizeLow
FileCount = FileCount + 1
If Len(FileName) <> 0 Then
Err.Clear
ChDir path & FileName
If Err = 0 Then
ReDim Preserve _
sFound(UBound(sFound) _
+ 1)
sFound(UBound(sFound) - _
1) = path & FileName
Err.Clear
End If
End If
End If
' Получить дескриптор следующего файла
Cont = FindNextFile(hSearch, WFD)
Wend
End If
Cont = FindClose(hSearch)
hSearch = FindFirstFile(path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DoEvents
DirName = StripNulls(WFD.cFileName)
' Пропустить текущую и родительскую папку.
If (DirName <> ".") And (DirName <> "..") Then
' Проверка на атрибуты.
If GetFileAttributes(path & DirName) And _
FILE_ATTRIBUTE_DIRECTORY Then
ReDim Preserve _
sFound(UBound(sFound) _
+ 1)
If Len(oldpath) <> 0 Then
sFound(UBound(sFound) - _
1) = Mid(path & DirName, Len(oldpath))
Else
sFound(UBound(sFound) - _
1) = Mid(path & DirName, Len(path))
End If
Debug.Print path & DirName
FindFilesAPI2 path & DirName, SearchStr, _
FileCount, DirCount, sFound(), path
End If
End If
'Перейти в следующую подпапку.
Cont = FindNextFile(hSearch, WFD)
Loop
Cont = FindClose(hSearch)
End If
End Function
Сейчас этот форум просматривают: The trick, Yandex-бот и гости: 12