Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileSearch for Folders (Word97/SR@)

    Can the FileSearch be used to obtain names of folders?

    No matter whether I use "msoFileTypeAllFiles" or "msoFileTypeBinders" I get 40 files.

    What IS a Binder, anyway?


    <pre>Sub test()
    Dim objFS As FileSearch
    Set objFS = Application.FileSearch
    With objFS
    .FileName = "c:*.*"
    ' .FileType = msoFileTypeAllFiles
    .FileType = msoFileTypeBinders
    .Execute
    MsgBox .FoundFiles.Count
    Dim i As Integer
    For i = 1 To .FoundFiles.Count
    Debug.Print .FoundFiles(i)
    Next i
    End With
    End Sub
    </pre>



    I'd dearly love to see this code point me to C:WINDOWS


    I can do it, so to speak, with DIR, just can't get it done with FileSearch.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: FileSearch for Folders (Word97/SR@)

    A binder is a container for office documents that a user can create. Not relevant to your needs.

    I think they call it Find Files for a reason... to find folders, you might prefer the FileSystemObject:

    <pre>Function GetFoldersAsString(strPath As String) As String
    ' Requires a reference set to Microsoft Scripting Runtime
    Dim fso As New FileSystemObject, fldrs As Folders
    Dim fldr As Folder_Class, strTemp As String
    Set fldrs = fso.GetFolder(strPath).SubFolders
    If fldrs.Count = 0 Then
    strTemp = vbNullString
    Else
    For Each fldr In fldrs
    strTemp = strTemp & fldr.Path & "|"
    Next
    End If
    GetFoldersAsString = strTemp
    End Function

    Sub TestFolders()
    MsgBox GetFoldersAsString("C:")
    End Sub</pre>

    I know you like strings, so I returned a string. Sadly, the folders are sorted by creation date... but I'm sure you will find a method that works for you. Hope this helps.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSearch for Folders (Word97/SR@)

    I have a sense of deja vu with this:

    Here's the routine, modifed to search for all files in drive C: (9,000+ as reported by a DOS DIR /S command) and it returns 13,000+, many of them from my partitions D: and F:.

    Weird.


    If you have more than one logical partition on your system, you may want to give it a spin, first opening up the Immediate window.

    I WOULDN'T RECOMMEND IT IF YOU ARE HOOKED UP TO A LAN - who knows who may come screaming at you.



    <pre>Sub test()
    Dim objFS As FileSearch
    Set objFS = Application.FileSearch
    With objFS
    .LookIn = "c:"
    ' .FileName = "c:*.*"
    .FileType = msoFileTypeAllFiles
    .SearchSubFolders = True
    .Execute
    MsgBox .FoundFiles.Count
    Dim i As Integer
    For i = 1 To .FoundFiles.Count
    On Error Resume Next
    If UCase(Left$(.FoundFiles(i), 1)) <> "C" Then
    Debug.Print .FoundFiles(i)
    Else
    End If
    Next i
    End With
    End Sub
    </pre>


  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSearch for Folders (Word97/SR@)

    Jefferson, thanks for this response.


    >A binder is a container for office documents

    Memories return. Odd that there are almost no references for it in a Google search.

    > you might prefer the FileSystemObject:

    Right. And thanks for the code snippet.

    I was toying with the idea of trying to use both the DIR and the FileSearch in tandem. Messy.



    Most of all I'd like something that returns me EVERYTHING and then lets me select things according to criteria.

    I'll report back ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •