Results 1 to 2 of 2
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    FileSearch for folders (Excel 97 to 2002)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Loungers

    OK what is the best way to use the FileSearch wrapper to find folders in a specific path and count them?

    I need to determine how many folders, their names, and sizes for an automated backup system that we are writing at work.

    I tried the Attribute 16, but maybe I did something wrong, it missed about 90% of the folder entries in my test path <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    Thanks for anyone who provides a sample code snipit.

    Wassim <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: FileSearch for folders (Excel 97 to 2002)

    Wassim,

    I think the FileSystem Object might be better suited. See if the following code can help in any way : <pre>Sub ListFolders(strPath As String)
    Dim fso As Object, fldr As Object, subFldr As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fldr = fso.GetFolder(strPath)
    Debug.Print fldr.Subfolders.Count
    For Each subFldr In fldr.Subfolders
    Debug.Print subFldr.Path, Format(subFldr.Size, "#,##0")
    <font color=blue>If subFldr.Subfolders.Count > 0 Then ListFolders (subFldr.Path)</font color=blue>
    Next
    Set subFldr = Nothing
    Set fldr = Nothing
    Set fso = Nothing
    End Sub

    Sub Test()
    ListFolders ("Data")
    End Sub</pre>

    The line in blue recursively calls the routine to provide a listing of nested folders, and can be omitted.

    Andrew C

Posting Permissions

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