[code]Public Function NameWithoutExtension(extends afi as FolderItem) as String
Dim completeName As String = afi.Name
If completeName="" Then Return completeName
Dim i As Integer = CountFieldsB(completeName,".")
Dim ext As String = NthFieldB( completeName, “.”, i)
’ completeName like “.xxxxxx”
If i>1 And InStrB(completeName, “.”) = 1 Then Return completeName
If i>1 Then Return LeftB(completeName, LenB(completeName)-LenB(ext)-1)
’ completeName without extension at all
Return completeName
End Function
[/code]
[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
If i>1 Then
ext = NthFieldB( ch, “.”, i)
Else
ext = “”
End If
[quote=442042:@Dave S]f.displayname returns the filename without the path
[/quote]
it depends on the user prefs. if the user asks to display all name with extension, then it does.
I thought it’d be a fun quick thought experiment, so here’s my version that applies the number to the file directly:
Public Sub ApplyNumber(fTarget as FolderItem, iNum as Integer)
// Sanity check
if fTarget = nil then return
if fTarget.Exists = false then return
dim arsFilenameParts() as String = Split(fTarget.Name, ".")
dim sFilename as String
dim sExt as String
// If we have enough parts, get the extension
if arsFilenameParts.Ubound > 0 then
sExt = "." + arsFilenameParts.Pop
end
// Rebuild the rest of the filename
sFilename = Join(arsFilenameParts, ".")
// Generate the new filename
dim sNewName as String = sFilename + "_" + str(iNum) + sExt
// Apply it
fTarget.Name = sNewName
End Sub
It returns whatever the user would see in the Finder / Explorer which may include the extension
If you set a file to NOT hide the extension the display name includes the extension
If by this you mean the path of the enclosing entity (dir, volume, etc)