Results 1 to 4 of 4

Thread: File types

  1. #1

    Thread Starter
    Addicted Member nota141's Avatar
    Join Date
    Feb 2000
    Location
    The place down there under everyone else.
    Posts
    224

    File types

    How can i get a list of a file with a file type in one directory. i would like a way that is done all through code
    On Error wake up and try again ;-)
    ___________________________
    ICQ # 65392645
    email - [email protected]

    Visual Studio 6 ent with SP5 Running on XP with an AMD 1.2 ThunderBird with 512 MB RAM And a 120GB primary HDD (very sweet)

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    I didn't quite understand the question, however, if you wanted a list of all the .tmp files in a directory, here is how to do it.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim a As Variant, i As Long
    
    a = EnumDir("c:", "tmp")
    
    If Not IsNull(a) Then
       For i = 1 To UBound(a)
          MsgBox a(i)
       Next i
    Else
        MsgBox "No files found In that directory matching " & _
            "the extension If you passed one."
    End If
    
    End Sub
    
    Function EnumDir(ByVal DirPath As String, Optional ByVal Ext As String) As Variant
        'Nucleus
        Dim files() As String: ReDim files(1 To 100)
        Dim fname$
        Dim lfcount&
        
        EnumDir = Null 'initialise Function
        
        If Right(DirPath, 1) <> "\" Then DirPath = DirPath & "\" 'add path separator If missing
        
        If Len(Dir$(DirPath, vbDirectory)) Then
        
            fname = Dir$(DirPath & "*.*", vbNormal + vbHidden + vbSystem) 'you can include vbdirectory If you need To
            Do While Len(fname)
                If Len(Ext) = 0 Or (Len(Ext) And Right(fname, Len(fname) - InStr(1, fname, ".")) = Ext) Then
                    lfcount = lfcount + 1
                    files(lfcount) = DirPath & fname 'path And file name To array
                    If lfcount Mod 100 = 0 Then ReDim Preserve files(1 To lfcount + 100) 'resize array As required
                End If
                fname = Dir$
            Loop
            
            If lfcount Then ReDim Preserve files(1 To lfcount): EnumDir = files
            
        End If
    End Function

  3. #3

    Thread Starter
    Addicted Member nota141's Avatar
    Join Date
    Feb 2000
    Location
    The place down there under everyone else.
    Posts
    224
    Thats what i was looking for

    can i get it to do sub dirs as well
    On Error wake up and try again ;-)
    ___________________________
    ICQ # 65392645
    email - [email protected]

    Visual Studio 6 ent with SP5 Running on XP with an AMD 1.2 ThunderBird with 512 MB RAM And a 120GB primary HDD (very sweet)

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

Posting Permissions

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



Click Here to Expand Forum to Full Width