Alias - Shortcut data help needed

In Windows.

I need to know the path and name of a shortcut when it is selected using the OpenFileDialog. My goal is to create a file in the same folder as the shortcut selected, then process the target file.

Everything seems to be the data for the target file of the shortcut.

Sub Pressed()
Var dlg As New OpenFileDialog
#If Not TargetLinux Then
dlg.InitialFolder = SpecialFolder.Documents
#Else ’ open Home directory on linux
dlg.InitialFolder = SpecialFolder.Home
#Endif
dlg.Title = “Select a MIF file”
//dlg.Filter = FileTypeGroup1.mif //Defined as file type in FileTypeGroup1.
Var f As FolderItem
f = dlg.ShowModal
If f <> Nil Then
’ proceed normally
Else
’ User Cancelled
End If
End Sub

Thanks!

If you use a file selector for that, the OS will resolve the alias / bookmark for you before you get a chance to use the folderitem.
If you know where the alias is, you can use specialfolder.documents.child(“thefilename”,false)
false says ‘dont resolve the alias’

But I understand there is (on Macs at least), another thing that looks to the user like an alias, but which is another type of redirection. It may not respect Xojo’s .IsAlias property.

That said, I’m struggling to imagine a use for ‘create a file in the same folder as the shortcut’ rather than the original document, but I’m sure you have your reasons.

You’re not thinking of hard links, perhaps? That’s a unix thing not really supported under macOS even though macOS is unix-based. A hard link is just another directory entry for the same physical file. The question, Which is the alias and which is the original file?, has no meaning AIUI.

Symbolic Links.

Sam had an interesting article on it:

https://ohanaware.com/blog/202104/Xojo-2020-Made-Mac-Apps-which-handle-Symbolic-Links-and-Bookmarks-Aliases.html

BUT, re-reading the OP’s question, they are on Windows, so not 100% relevant to the original question.

1 Like

And, before writing there (at alias location), check if you have the permissions to write…

I have a variety of data files (csv, tsv) on remote file servers (unc) that are in folders not writeable by my clients, and not easily found by the inexperienced ones. My project creates a subfolder in the users profile. In there, I have shortcuts to the data files, and a config file for each specifying how to handle the data. The config file is to be written to the folder containing the shortcut, and named similar to the shortcut file name (myData.lnk has a corresponding myData.ini).

I’m able to make use of dragging and dropping these shortcuts and achieve all of the above. DropObject exposes the alias info.

Obviously I can rewrite all of this in some other way, but this way would be optimal for the desired experience.

I wrote that article nearly 3 years ago, because of the change of bug reporting the link is broken, but I wonder if Xojo fixed the bug in their new framework yet?

1 Like

So the question is, Does OpenFileDialog always resolve shortcuts?

Edit: The SelectedFiles method appears to have an option to not resolve them. Instead of using the return value from dlg.ShowModal, use

for each f as FolderItem in dlg.SelectedFiles(False)

I’m trying the below, but it doesn’t give me the alias, it gives me the target.

The shortcut name here is ‘_GoogleUsers.txt - Shortcut.lnk’
The target is ‘_GoogleUsers.txt’

Var dlg As New OpenFileDialog

dlg.InitialFolder = app.ExecutableFile.Parent

dlg.Title = "Select a file"
dlg.AllowMultipleSelections = true

Var f As FolderItem
f = dlg.ShowModal


If f <> Nil Then
  
  For Each file As Folderitem In dlg.SelectedFiles(False)
    Listbox1.AddRow(file.Name)
  Next
  
Else
  ' User Cancelled
End If

… and the Alias property shows ‘False’ in the debug pane too… nothing here to show it’s a shortcut.

1 Like

I do not think so. The correct way is to give training to the users, so they will know how to use their computer.

But, this is just my opinion.

They are actually supported:

Also, a shortcut file would have a .lnk extension.

What are you basing your conclusion on? You don’t know the use case, you don’t know the user population, you don’t know the users feedback, and you don’t know the availability of participants for training.

A hard link in macOS/unix/linux is an extra directory entry for a file. It is not, itself, a file. Your linked article didn’t seem to understand that. That is why if you make a hard link to a file, it will appear to be a copy with the same size as the original, but it is actually pointing at the original file. This is similar to object references in Xojo, and, as with Xojo, a file is not actually deleted until its reference count is zero.

Now, Finder does not understand this and so will get confused about how much disk space is used, if you had previously gone into Terminal and hard-linked some files. Hard links were not used in macOS except for Time Machine, where thery were cleverly used to make an incremental backup look like a full backup. Whether TM still does this I don’t know.