RE: Understanding Dir() function

From: Joe (Joe_at_discussions.microsoft.com)
Date: 08/27/04


Date: Fri, 27 Aug 2004 06:21:02 -0700

Never mind. I got it.

"Joe" wrote:

> I have been using the following code (supplied by Tim Baur) to recurse
> through the directories of a drive in search of all instances of a file (i.e.
> aFile.txt).
>
> What I don't understand is once I've retrieved the root directory of the
> drive and am processing through the Do...Loop, why does sItem = Dir() return
> the files in the root directory since I began the Do...Loop wth
> Dir(sStartDir, vbDirectory)? I thought that the Dir() function should only
> return files (or directories in this case) that match the search criteria in
> the Dir() function.
>
> Can anyone help with this?
>
> Here's the code:
>
> [snip]
>
> 'retrieve the first directory
> sItem = Dir(sStartDir, vbDirectory)
> Do
> If sItem <> "." And sItem <> ".." And sItem <> vbNullString Then
> sItems = sItems & "|" & sItem
> End If
> sItem = Dir()
> Loop Until sItem = vbNullString
>
> sItemArr = Split(sItems, "|")
>
> For i = 1 To UBound(sItemArr)
> sItem = sItemArr(i)
> iAttr = GetAttr(sStartDir & sItem)
> If iAttr >= vbDirectory And iAttr < vbArchive Then
> SearchFile = SearchFile(sFile, sStartDir & sItem)
> If SearchFile <> vbNullString Then Exit For
> Else
> If sItem = sFile Then
> SearchFile = sStartDir & sItem
> Exit Function
> End If
> End If
> Next i
> --
>
> TIA,
> Joe
>
> VBA Automation/VB/C++/Web and DB development



Relevant Pages

  • Understanding Dir() function
    ... I have been using the following code to recurse ... What I don't understand is once I've retrieved the root directory of the ... drive and am processing through the Do...Loop, why does sItem = Dirreturn ... Dir(sStartDir, vbDirectory)? ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem with my sound card creative when start windowsxp
    ... > thanks the MSConfig helped me to get to the root directory ... Either way, glad you have it sorted, Joe. ... >>> When the Creative program comes up at Windows Startup, ... it make my machine slower. ...
    (microsoft.public.windowsxp.general)
  • Re: C Drive Icon double click opens ACDSee
    ... the root directory, when Right-clicking the icon, it show the options ... Fix File Associations. ... Joe =o) ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: C Drive Icon double click opens ACDSee
    ... the root directory, when Right-clicking the icon, it show the options ... Fix File Associations. ... Joe =o) ...
    (microsoft.public.windowsxp.help_and_support)