Difficulties with FolderItem extension

So far I have used the code from the documentation of SaveFileDialog (https://docs.xojo.com/SaveFileDialog) to call the other correct method based on the file extension. This also works without problems under macOS/Windows.
Then yesterday, I tried the code on Linux (Mint 19.2, Fedora 28, Deepin 15.11, Elementary) and found that the code does not fire because FolderItem.Name is returned without a file extension despite the file extension being set (dropdown list in dialog). Does anyone have a suggestion on how I can achieve consistency on Linux?

My code:

Var dlg As New SaveFileDialog
dlg.InitialFolder = SpecialFolder.Desktop
dlg.Filter = FileTypeGroup1.Pdf + FileTypeGroup1.PlainText

Var file As FolderItem
file = dlg.ShowModalWithin(Self)

If Not (file Is Nil) Then
  #Pragma Warning "Linux does not add the extension in file.Name - So Action-Event doesn't work."
  Var sName As String = file.Name
  If sName.Right(3) = "pdf" Then
   ' PDF Method
  ElseIf sName.Right(3) = "txt" Then
   ' TXT Method
  End If
End If


@William_Yu, this is a true bug on Linux. I’ve created a feedback ticket with a sample project: feedback://showreport?report_id=63593

Var dlg As New SaveFileDialog ' OpenFileDialog works as expected.
dlg.InitialFolder = SpecialFolder.Desktop
dlg.Filter = FileTypeGroup1.All ' or 
' dlg.Filter = FileTypeGroup1.Pdf + FileTypeGroup1.Rtf

Var file As FolderItem
file = dlg.ShowModalWithin(Self)

If Not (file Is Nil) Then
  Var sName As String = file.DisplayName
  System.DebugLog sName
  System.DebugLog file.Name
  System.DebugLog file.NativePath
  System.DebugLog file.ShellPath
  System.DebugLog file.URLPath
  If sName.Right(3) = "rtf" Then
    ' Do something. Won't break.
  Elseif sName.Right(3) = "pdf" Then
    ' Do something. Won't break.
  End If
End If
1 Like

Someone recently adviced me to use Select Case instead of If ElseIf construct.

This is also a good case for use Select Case (you add easilly a new file type to the block and still can read it…

1 Like

Yeah i know. This is only to show the case. Using Select Case ends in the same bug.

Yes, I understand.

USE file.Name instead of DsplayName: it is not a bug n Linux, but in the two other OSes that return Name + File Extension (DsplayName).

All Path return no file Extension ?

With Select Case you would use:

Select Case sName

Case sName.Right(20) = ".xojo_binary_project"
// It’s a Xojo Binary File !

Case sName.Right(3) = "rtf"

etc. If I do not make a mistake.

Sorry to say, it’s a bug. FolderItem.Name is what I used before FolderItem.DisplayName as you can see in my first post and if you look in the DebugLog, you’ll see FolderItem.Name also returns the Name without Extension, also like all FolderItem...Path properties. I tested this into the deep with four different Linux OS. We’ll see what @William_Yu can do.

Sorry: I read your text too fast…

Sight ! I was happy to found a solution and now it is trully a bug ! :frowning:

I have tears in my eyes.

Sorry, I had to remove my VirtualBoxes to get rooms in my small SSD, so I cannot check.

Are XxxPath displaying the file extension ?
(I suppose not, else a workaround exist)


OK: no more idea. Sorry.

Yes ! I’ve got another (I hope this time…)

What about using the terminal ?

ls on MacOS (El Capitan) returns the file extension. With a little luck, maybe…

This has been fixed today by Xojo. Thread can be closed.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.