Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316

    Unanswered: Count files of certain type

    I have the following code to count the number of files in a folder:

    Code:
    Dim fso As New FileSystemObject
    Dim fls As Files
    Dim intFileCount As Integer
    
    Set fls = fso.GetFolder(strSaveLoc).Files
    
    intFileCount = fls.Count
    How can I change this to count only files with a certain extension?

    Thanks in advance for any help.

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    I wrote this function
    Code:
        Function Get_File_Count(ByVal FolderName As String) As Long
            ' **********************************************************
            ' Inputs FolderName = folder name
            '        Return  = Count count of ones I don't want to know
            ' **********************************************************
            Dim Ver, MaxVer, File_Name, folder, FSO, Files
            Dim Items As Object
            Get_File_Count = 0
            FSO = CreateObject("Scripting.FileSystemObject")
            folder = FSO.GetFolder(FolderName)
            Files = folder.Files
            Dim FileCount = Files.count
            Dim ind, hed, txt, db, bl As Long
            For Each Items In Files
                If Items.Type = "InDesign Document" Then ind = ind + 1
                If Items.Type = "HED File" Then hed = hed + 1
                If Items.Type = "Text Document" Then txt = txt + 1
                If Items.Type = "Data Base File" Then db = db + 1
                If Items.Type = "File" Then bl = bl + 1
            Next
            Get_File_Count = FileCount - (ind + hed + txt + db + bl)
    
            FSO = Nothing
            folder = Nothing
            Files = Nothing
        End Function
    You can see How I counted the Differance type of file in a folder.
    Last edited by myle; 06-28-06 at 16:27.
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Thanks a lot for that. Out of pure curiosity, does anyone know of a more succinct method without having to use the loop?

  4. #4
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    Something have to loop and count

    computer an't that smart yet

    How meny red pens on your desk don't count
    that what you are asking the computer to do
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  5. #5
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Well, after some toil, I managed to find a very minimal way of doing it:

    Code:
    Dim lngFileCount As Long
    Dim StrFileName As String
    
    strFileName = Dir$("N:\*.doc")
    Do While Len(strFileName) <> 0
        lngFileCount = lngFileCount + 1
        strFileName = Dir$
    Loop

Posting Permissions

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