Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i find a file extention?

Status
Not open for further replies.

mackey333

Technical User
Joined
May 10, 2001
Messages
563
Location
US
how can i figure out what the extention of a given file is? -Greg :-Q

flaga.gif
 
Code:
Option Explicit

Sub main()
  Dim sFile As String
  Dim oFSO As Scripting.FileSystemObject
  
  sFile = "C:\autoexec.bat"
  
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  MsgBox oFSO.GetExtensionName(sFile)
  Set oFSO = Nothing
  
  MsgBox ExtName(sFile)
End Sub

Private Function ExtName(ByVal sFile As String) As String
  Dim nWhere As Long
  
  Debug.Print sFile
  nWhere = InStrRev(sFile, "\")
  If nWhere > 0 Then
    sFile = Mid$(sFile, nWhere + 1)
    Debug.Print sFile
  End If
  nWhere = InStrRev(sFile, ".")
  If nWhere > 0 Then
    sFile = Mid$(sFile, nWhere + 1)
    Debug.Print sFile
    ExtName = sFile
  End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top