Get File Extension from FolderItem

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

Not built in, sorry.

[code]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
[/code]
and

[code]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
[/code]

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

Cool. Thanks

A true DisplayName !

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

[code]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
[/code]

I would not use something with declares (or plugins) when you can do it easy with xojo language … :wink:

1 Like

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

I just wanted the practice :slight_smile:

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