Consulting

Results 1 to 6 of 6

Thread: Get count of all .dot files in folder and its subfolders?

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Get count of all .dot files in folder and its subfolders?

    Can a macro count all the .dot files in a particular folder and all it's subfolders?

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yes.

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    That's good to know. Can you help me figure out how to do it?

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    How about this?

    David


  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Use FileSearch, but it does not have to be as complicated as Kens example.

    If you just want a count.....[vba]
    With Application.FileSearch
    .FileName = ".dot"
    .LookIn = "c:\test"
    .SearchSubFolders = True
    .Execute
    If .FoundFiles.Count > 0 Then
    Msgbox .FoundFiles.Count & " dot files found."
    End If
    End With
    [/vba]

    Or....

    [vba]Dim var
    Dim msg As String
    With Application.FileSearch
    .FileName = ".dot"
    .LookIn = "c:\test"
    .SearchSubFolders = True
    .Execute
    If .FoundFiles.Count > 0 Then
    For var = 1 To .FoundFiles.Count
    msg = msg & .FoundFiles(var) & _
    vbCrLf
    Next
    End If
    End With
    Selection.TypeText Text:=msg
    [/vba]which would type in the full path and names. NOTE however, that the listing will be by the alphabetical order of the filenames, NOT the folder/subfolder. For example, here is the output of the above.

    C:\Test\Appointment Template Gerry.dot
    C:\Test\Appointment Template Health CentreGJK.dot
    C:\Test\Change_Observation_Ver._7.1.dot
    C:\Test\VBA_WorkDocs\checkvar.dot
    C:\Test\CVConversion.dot
    C:\Test\DifferentHeaders.dot
    C:\Test\PPRTemplate.dot
    C:\Test\test2\Restart NumberingGerry.dot
    C:\Test\tektips.dot
    C:\Test\VBA_WorkDocs\VBAExpress.dot

    Notice that checkvar.dot (in the subfolder VBA_WorkDocs) is listed before CVConversion.dot (in the folder above it).

    You can of course have things listed by folder...but really, Cheryl, what did you attempt yourself?

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    OK, OK, here is how you get the result that will do it by searched folder, not filename.
    [vba]
    Dim var
    Dim msg As String
    With Application.FileSearch
    .FileName = ".dot"
    .LookIn = "c:\test"
    .SearchSubFolders = True
    .Execute (msoSortByNone)
    If .FoundFiles.Count > 0 Then
    For var = 1 To .FoundFiles.Count
    msg = msg & .FoundFiles(var) & _
    vbCrLf
    Next
    End If
    End With
    Selection.TypeText Text:=msg[/vba]

    Result:

    C:\Test\Appointment Template Gerry.dot
    C:\Test\Appointment Template Health CentreGJK.dot
    C:\Test\Change_Observation_Ver._7.1.dot
    C:\Test\CVConversion.dot
    C:\Test\DifferentHeaders.dot
    C:\Test\PPRTemplate.dot
    C:\Test\tektips.dot
    C:\Test\test2\Restart NumberingGerry.dot
    C:\Test\VBA_WorkDocs\checkvar.dot
    C:\Test\VBA_WorkDocs\VBAExpress.dot

    Notice the order is:

    C:\Test
    C:\Test\test2
    C:\Test\VBA_WorkDocs

Posting Permissions

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