Ecco a te quello che hai chiesto:
Codice:
Option Explicit
Private Const MAX_PATH = 260
Private Const INVALID_HANDLE_VALUE = -1
Private Const FILE_ATTRIBUTE_DIRECTORY = &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" 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 sVetFile() As String
Private Sub Form_Load()
ReDim sVetFile(0)
Call FindFilesAPI("G:\Y2K\UBL Team\Logo")
End Sub
Private Sub FindFilesAPI(ByVal sPath As String)
Dim sName As String
Dim bFound As Boolean
Dim hSearch As Long
Dim WFD As WIN32_FIND_DATA
'controllo formato parametro
If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
bFound = True
hSearch = FindFirstFile(sPath & "*.*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While bFound
DoEvents
sName = Left$(WFD.cFileName, InStr(WFD.cFileName, Chr$(0)) - 1)
'ignoro le directory . e ..
If (sName <> ".") And (sName <> "..") Then
'seleziono la direcoty o il file
If GetFileAttributes(sPath & sName) And FILE_ATTRIBUTE_DIRECTORY Then
'gestione delle cartelle
Else
sVetFile(UBound(sVetFile)) = sPath & sName
ReDim Preserve sVetFile(UBound(sVetFile) + 1)
End If
End If
bFound = FindNextFile(hSearch, WFD) 'avanzo al prossimo file/cartella
Loop
bFound = FindClose(hSearch)
End If
End Sub