Results 1 to 4 of 4

Thread: Wildcards using FileSystemObject or whatever

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    norcross, ga, USA
    Posts
    82

    Post

    Question: Creating app that will give me just the file name of any file in a specified directory with the extension .rar.

    FSO doesn't seem to understand wildcards in VB. Is there a way to make it give me back just the file name? The File name will never be the same.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Post

    Try this:

    Public Function GetRARFile(sPath As String) As String
    Dim sFile$
    sPath = sPath & IIf(Right$(sPath, 1)<>"\", "\", "")
    sFile = Dir(sPath & "*.rar")
    If Len(sFile) Then
    GetRARFile = Mid$(sFile, InStrRev(sFile, "\") + 1)
    End If
    End Function

    Good luck!

    ------------------
    Joacim Andersson
    [email protected]
    [email protected]
    www.YellowBlazer.com



  3. #3
    Guest

    Post

    1. start new project
    2. add a command button named command1 to the form
    3. reference the scripting run time
    4. cut and paste the following in the code module of the form:

    Option Explicit


    Private Sub Command1_Click()
    FindFilesWithExtension "tmp", "c:\temp"
    End Sub

    Public Sub FindFilesWithExtension(ByVal strExtensionToFind, ByVal strDirectoryToSearch)

    Dim fso As Scripting.FileSystemObject
    Dim fsoFile As Scripting.File

    Set fso = New Scripting.FileSystemObject

    For Each fsoFile In fso.GetFolder(strDirectoryToSearch).Files
    If fso.GetExtensionName(fsoFile) = strExtensionToFind Then
    Debug.Print fso.GetExtensionName(fsoFile)
    End If
    Next

    Set fso = Nothing

    End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    norcross, ga, USA
    Posts
    82

    Post

    Thanks for your help guys! That was exactly what I needed!

    <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
  •  



Click Here to Expand Forum to Full Width