Get File Extension from FolderItem

  1. 3 years ago

    Oliver S

    22 Jan 2017 North Yorkshire, United Kingdo...

    Is there a built-in method or property that I can use to grab the extension off of the file name. For example mp3 files would compare like:
    myFolderItem.ExtensionName

    I know I could use string methods to grab the last '.'. but was just wondering if this function was built-in.

    Thanks

  2. Emile S

    22 Jan 2017 Europe (France, Strasbourg)

    Not built in, sorry.

  3. Jean-Yves P

    22 Jan 2017 Pre-Release Testers, Xojo Pro Europe (France, Besançon)
    Public Function NameWithoutExtension(extends afi as FolderItem) as String
      dim ch as String = afi.Name
      dim i as Integer = CountFieldsB(ch,".")
      dim ext as String = NthFieldB( ch, ".", i)
      
      Return LeftB(ch, LenB(ch)-LenB(ext)-1)
      
    End Function

    and

    Public Function ExtensionName(extends afi as FolderItem) as String
      dim ch as String = afi.Name
      dim i as Integer = CountFieldsB(ch,".")
      dim ext as String = NthFieldB( ch, ".", i)
      
      Return ext
      
    End Function
  4. Tim P

    22 Jan 2017 Pre-Release Testers, Xojo Pro Rochester, NY

    If you happen to have MBS there is a MBS function for it.

  5. Oliver S

    22 Jan 2017 North Yorkshire, United Kingdo...

    Cool. Thanks

  6. Emile S

    22 Jan 2017 Europe (France, Strasbourg)

    @Jean-YvesPochez NameWithoutExtension

    A true DisplayName !

  7. Julian S

    22 Jan 2017 Pre-Release Testers, Xojo Pro UK

    My first ever macos declare :) Sorry, no linux love at the moment.

    Public Function Extension(extends fi as FolderItem) as String
      #If TargetWindows
        Declare Function PathFindExtensionW Lib "Shlwapi.dll" (pszPath As WString) As WString
        Dim tmp As String = PathFindExtensionW(fi.Name)
        Return Right(tmp, Len(tmp)-1)
      #ElseIF TargetMacOS
        Declare function pathExtension lib "Foundation" selector "pathExtension" (inString as CFStringRef) as CFStringRef
        Return pathExtension(fi.Name)
      #Endif
      
    End Function
  8. Jean-Yves P

    23 Jan 2017 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    I would not use something with declares (or plugins) when you can do it easy with xojo language ... ;)

  9. Julian S

    23 Jan 2017 Pre-Release Testers, Xojo Pro UK

    Neiter would I unless it was quicker, which it isnt.

    I just wanted the practice :)

  10. Thomas R

    25 Jan 2017 Europe, France, Besancon

    I discover ByRef in another topic. You can use it to obtain in one time the name without extension and the extension.

    Sub NameExt(MyItem as FolderItem, ByRef NameWithoutExt as String, ByRef ItemExt as String)
    ItemExt =  code written by Jean-Yves
    NameWithoutExt = code written by Jean-Yves


    exemple of ByRef

  11. 2 weeks ago

or Sign Up to reply!