Results 1 to 7 of 7

Thread: [RESOLVED] Filename Extension

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Resolved [RESOLVED] Filename Extension

    how to get the file Extension name but without the "."?
    io.path.getextension returns with the "."

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Filename Extension

    Why not just use the substring function to remove the "."?

    Code:
            Dim MyPath As String = "c:\SomeFolder\Readme.txt"
            Dim Extension As String = IO.Path.GetExtension(MyPath)
            Extension = Extension.Substring(1, Extension.Length - 1)

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Filename Extension

    Code:
            Dim MyPath As String = "c:\SomeFolder\Readme.txt"
            Dim Extension As String = IO.Path.GetExtension(MyPath).Remove(0, 1)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Filename Extension

    Yet another way
    Code:
    Dim MyPath As String = "c:\SomeFolder\Readme.txt"
    Dim Extension As String = IO.Path.GetExtension(MyPath).Replace(".", "")
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Filename Extension

    Replace is more inefficient because it searches the whole 4-character extension.

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Filename Extension

    Yeah I think dbasnett's example is the best way to go, I was just point out another way it could be done
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Filename Extension

    thanks for the quick reply guys.. + for you all

Tags for this Thread

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