Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Const INVALID_HANDLE_VALUE As Long = -1
- Private Const MAX_PATH As Long = 260
- Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
- 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 Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, ByRef lpFindFileData As WIN32_FIND_DATA) As Long
- Private Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As Long, ByRef lpFindFileData As WIN32_FIND_DATA) As Long
- Private Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
- Private Sub ObjectFound(IsDirectory As Boolean, Name As String)
- If IsDirectory Then Name = "[" & Name & "]"
- MsgBox Name
- End Sub
- Private Function GoEnum(Path As String, Recursive As Boolean) As Boolean
- 'This function returns TRUE if it has failed, otherwise FALSE.
- Dim fd As WIN32_FIND_DATA, IsDir As Boolean
- Dim hFind As Long, Name As String, Res As Boolean
- hFind = FindFirstFile(Path & "*.*", fd)
- If hFind <> INVALID_HANDLE_VALUE Then
- Res = True
- Do
- Name = Left$(fd.cFileName, InStr(1, fd.cFileName, vbNullChar) - 1)
- If Len(Name) > 0 And Name <> "." And Name <> ".." Then
- If (fd.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = 0 Then
- Call ObjectFound(False, Path & Name)
- Else
- Name = Name & "\"
- Call ObjectFound(True, Path & Name)
- If Recursive Then Res = Res And Not (GoEnum(Path & Name, True))
- End If
- End If
- Loop While FindNextFile(hFind, fd) <> 0
- FindClose hFind
- GoEnum = Res
- Else
- GoEnum = True
- End If
- End Function
- Public Function Enumerate(ByVal Path As String, Optional Recursive As Boolean = False) As Boolean
- Path = Replace$(Path, "/", "\")
- If Right$(Path, 1) <> "\" Then Path = Path & "\"
- Enumerate = GoEnum(Path, Recursive)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement