Click to See Complete Forum and Search --> : Wildcards using FileSystemObject or whatever
cvaden
Jan 13th, 2000, 04:31 PM
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.
Joacim Andersson
Jan 13th, 2000, 08:07 PM
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
joacim@programmer.net
joacim@yellowblazer.com
www.YellowBlazer.com (http://www.YellowBlazer.com)
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
cvaden
Jan 17th, 2000, 03:47 AM
Thanks for your help guys! That was exactly what I needed!
<c>
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.