Re: FindFirstFile demo at MVPS

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Stu (saet_at_steh.szerg)
Date: 09/23/04


Date: Thu, 23 Sep 2004 14:09:23 +0100


> Depends what you mean by "the first x files". If you simply mean the
first
> x number of files found by FindFirst/FindNext, then just yes. Simply keep
a
> counter and quit searching when you've reached that count.

This is exactly what I mean! But I can not figure out where to count the
files. The obvious place is where the file is added to the list box but
because of the recursion I cant figure out how to stop the search once
lFoundFiles > x.

E.g. I have

GetFileInformation
...
...
If FP.Count >= lFileLimit Then
  bStop = True 'Module level flag to stop searching
Else
  sTmp = TrimNull(WFD.cFileName)
  Debug.Print sRoot & sTmp
End If
...
...

Then I wrap the recursion in an if statement using the bStop flag:
SearchForFiles
...
...
...
'if valid ...
   If hFile <> INVALID_HANDLE_VALUE Then

     'This is where the method obtains the file
     'list and data for the folder passed.
      Call GetFileInformation(FP)

      If Not bStop Then
          Do

            'if the returned item is a folder...
             If (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
                ...
                ...

Now if I search "r*" starting at "C:\" I get 11 files found when lFileLimit
= 2! What I want is a recursive findFirstFile to find the 1st occurrence of
a file. Once one file has been found I want to stop searching.

Also is this algorithm efficient for searching a limited no of files? I
think it is doing a depth first search (i.e. go down all folders first
before looking at the files).

Any ideas?

Cheers
Stu



Relevant Pages

  • RE: Getting file name and Modified date
    ... enumerate the files in the starting folder ... End Sub ... If you don't like using recursion, you could use the command line Dir ... Try searching this group, I'm sure you will find some examples. ...
    (microsoft.public.excel.programming)
  • Recursion in VBA macros?
    ... financial data. ... When I'm searching an almost full column for the next non-blank entry I ... Are there any guidelines for using recursion under VBA? ...
    (microsoft.public.excel.programming)