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.
VB Code:
  1. Option Explicit
  2. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  3. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  4. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
  5. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  6.  
  7. Const FILE_ATTRIBUTE_DIRECTORY = &H10
  8.  
  9. Private Type FILETIME
  10.   dwLowDateTime As Long
  11.   dwHighDateTime As Long
  12. End Type
  13.  
  14. Private Type WIN32_FIND_DATA
  15.   dwFileAttributes As Long
  16.   ftCreationTime As FILETIME
  17.   ftLastAccessTime As FILETIME
  18.   ftLastWriteTime As FILETIME
  19.   nFileSizeHigh As Long
  20.   nFileSizeLow As Long
  21.   dwReserved0 As Long
  22.   dwReserved1 As Long
  23.   cFileName As String * 260
  24.   cAlternate As String * 14
  25. End Type
and the sub
VB Code:
  1. Private Sub showallfiles(spath As String)
  2. Dim sdir As String, dirarr() As String, x As Integer
  3. Dim i As Integer, sh As Long, OK As Boolean
  4. Dim wfd As WIN32_FIND_DATA
  5.    
  6.     If Right$(spath, 1) <> "\" Then spath = spath & "\"
  7.     OK = True
  8.    
  9.     sh = FindFirstFile(spath & "*.*", wfd)
  10.     If sh <> -1 Then
  11.         Do While OK
  12.           sdir = Left$(wfd.cFileName, InStr(wfd.cFileName, Chr(0)) - 1)
  13.             If (sdir <> ".") And (sdir <> "..") Then
  14.               If GetFileAttributes(spath & sdir) And FILE_ATTRIBUTE_DIRECTORY Then
  15.                 ReDim Preserve dirarr(x)
  16.                 dirarr(x) = spath & sdir & "\"
  17.                 x = x + 1
  18.               Else
  19.                List1.AddItem spath & sdir
  20.               End If
  21.             End If
  22.           OK = FindNextFile(sh, wfd)
  23.         Loop
  24.           FindClose sh
  25.     End If
  26.        
  27.    For i = 0 To x - 1
  28.     showallfiles dirarr(i)
  29.    Next i
  30. End Sub
thank you.
casey.