Finding the extension of a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vdraceil
    New Member
    • Jul 2007
    • 236

    Finding the extension of a file

    Hi,does anyone know how to find the extension of a file knowing only the name of the file?to be more clear,i want to know the extension of some file with its path and file name-"C:\folder\file "..How do i do it by coding in vb6.0?
  • mafaisal
    New Member
    • Sep 2007
    • 142

    #2
    Hello,

    Try The Following

    Dim ExtName as string
    Dim FileName as string
    FileName = "Test.Txt" ' for example

    ExtName = Mid(FileName ,InStrRev(FileN ame , ".")+1, Len(FileName ))

    then got ExtName = "Txt"

    If not this plz ignore

    Faisal

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      Originally posted by mafaisal
      Hello,

      Try The Following

      Dim ExtName as string
      Dim FileName as string
      FileName = "Test.Txt" ' for example

      ExtName = Mid(FileName ,InStrRev(FileN ame , ".")+1, Len(FileName ))

      then got ExtName = "Txt"

      If not this plz ignore

      Faisal
      Hi mafaisal,i think u didnt get my question.U've just taken FileName="Test. txt".My question was if i know a file name(just the name and not its extension) and its correct path,can i find its extension using VB6.0?.Take FileName="C:\Fo lder\File".I want to find the extension of the file "File".

      Comment

      • mafaisal
        New Member
        • Sep 2007
        • 142

        #4
        Hello
        Ok Understand

        Try this

        Add reference microsoft scripting runtime

        Code:
        Dim FSO As New FileSystemObject
        Dim F1 As File
        Dim FOL As Folder
        Set FOL = FSO.GetFolder(Path of File)
        Dim Ext
        For Each F1 In FOL.Files
         Ext = Split(F1.Name, ".")
         MsgBox Ext(1)
        Next

        Hope this will Help u

        Faisal

        Originally posted by vdraceil
        Hi mafaisal,i think u didnt get my question.U've just taken FileName="Test. txt".My question was if i know a file name(just the name and not its extension) and its correct path,can i find its extension using VB6.0?.Take FileName="C:\Fo lder\File".I want to find the extension of the file "File".

        Comment

        Working...