Tilføj et modul til dit projekt, og paste følgende kode i det
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 Const MAX_PATH = 260
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
Public Sub ListSubdirs(Box As ListBox, sDir As String)
Dim h As Long
Dim FindData As WIN32_FIND_DATA
Dim bFiles As Boolean
Dim File As String
bFiles = True
h = FindFirstFile(sDir & "\\*.*", FindData)
While bFiles
File = FindData.cFileName
File = Left(File, InStr(1, File, vbNullChar) - 1)
If Not (File = "." Or File = "..") Then
If FindData.dwFileAttributes = vbDirectory Then
'we have a dir
Box.AddItem (FindData.cFileName)
End If
End If
bFiles = FindNextFile(h, FindData)
Wend
End Sub
for at liste submapper i dit programs sti, skal du kalde sub'en sålades:
Call ListSubDirs(List1, App.Path)
list1 skal selfølgelig ændres til navnet på dit Listbox
Mvh,
Thomas Nielsen