Hi All.
I use the below code to search for files of a given type in my program..some of the users have asked for a progress bar to see where the search is at only I have NO idea where to insert the bit of code do do this can any one help please
VB Code:
  1. Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
  2. 'On Error GoTo trap:
  3.  
  4.      ' Walking filename variable...
  5.     Dim DirName As String ' SubDirectory Name
  6.     Dim dirNames() As String ' Buffer for directory name entries
  7.     Dim nDir As Integer ' Number of directories in this path
  8.     Dim i As Integer ' For-loop counter...
  9.     Dim hSearch As Long ' Search Handle
  10.     Dim WFD As WIN32_FIND_DATA
  11.     Dim Cont As Integer
  12.     If Right(path, 1) <> "\" Then path = path & "\"
  13.     ' Search for subdirectories.
  14.     nDir = 0
  15.     ReDim dirNames(nDir)
  16.     Cont = True
  17.     hSearch = FindFirstFile(path & "*", WFD)
  18.     If hSearch <> INVALID_HANDLE_VALUE Then
  19.         Do While Cont
  20.         DirName = StripNulls(WFD.cFileName)
  21.         ' Ignore the current and encompassing directories.
  22.         If (DirName <> ".") And (DirName <> "..") Then
  23.             ' Check for directory with bitwise comparison.
  24.             If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
  25.                 dirNames(nDir) = DirName
  26.                 DirCount = DirCount + 1
  27.                 nDir = nDir + 1
  28.                 ReDim Preserve dirNames(nDir)
  29.             End If
  30.         End If
  31.         Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
  32.         Loop
  33.         Cont = FindClose(hSearch)
  34.     End If
  35.     ' Walk through this directory and sum file sizes.
  36.     hSearch = FindFirstFile(path & SearchStr, WFD)
  37.     Cont = True
  38.     If hSearch <> INVALID_HANDLE_VALUE Then
  39.         While Cont
  40.             FileName = StripNulls(WFD.cFileName)
  41.             If (FileName <> ".") And (FileName <> "..") Then
  42.                 FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
  43.                 FileCount = FileCount + 1
  44.                 lstFilesfound.AddItem path & FileName
  45.                 DoEvents
  46.             End If
  47.             Cont = FindNextFile(hSearch, WFD) ' Get next file
  48.         Wend
  49.         Cont = FindClose(hSearch)
  50.     End If
  51.     ' If there are sub-directories...
  52.     If nDir > 0 Then
  53.         ' Recursively walk into them...
  54.         For i = 0 To nDir - 1
  55.             FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
  56.         Next i
  57.     End If
  58. 'End Function
  59.  
  60. 'trap:
  61. 'Call crash
  62.  
  63. End Function


many thanks Chris