i have tried to cut down the findfirst, findnext api for finding all files and subfolder files in a given path, i have cut it down to the bare minimum required because all the examples i see have loads of other stuff with them. can you check over it and see if i have missed anything or where it could be better please.
and the subVB Code:
Option Explicit 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 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 * 260 cAlternate As String * 14 End Type
thank you.VB Code:
Private Sub showallfiles(spath As String) Dim sdir As String, dirarr() As String, x As Integer Dim i As Integer, sh As Long, OK As Boolean Dim wfd As WIN32_FIND_DATA If Right$(spath, 1) <> "\" Then spath = spath & "\" OK = True sh = FindFirstFile(spath & "*.*", wfd) If sh <> -1 Then Do While OK sdir = Left$(wfd.cFileName, InStr(wfd.cFileName, Chr(0)) - 1) If (sdir <> ".") And (sdir <> "..") Then If GetFileAttributes(spath & sdir) And FILE_ATTRIBUTE_DIRECTORY Then ReDim Preserve dirarr(x) dirarr(x) = spath & sdir & "\" x = x + 1 Else List1.AddItem spath & sdir End If End If OK = FindNextFile(sh, wfd) Loop FindClose sh End If For i = 0 To x - 1 showallfiles dirarr(i) Next i End Sub
casey.




Reply With Quote