ln -s

I have created some LINK’s with:

shell.Execute( "ln -s " + inputTileFolder.ShellPath + " " + outputFolder.ShellPath )

How will FolderItem show me if something is a LINK instead of a real folder or file?

[quote]Aliases
If a FolderItem is actually an alias to a FolderItem, the alias is automatically resolved when the FolderItem is accessed unless you use TrueChild and TrueItem. They return the item itself, even if it is an alias. Use the Alias property to determine whether the FolderItem is an alias.[/quote]

http://developer.xojo.com/folderitem

a LINK is not the same as an ALIAS in macOS

Also, both classes are showing the same info in the debugger:

dim f1 as FolderItem = GetTrueFolderItem(outputFolder.Child(Tile).ShellPath, FolderItem.PathTypeShell) dim f2 as FolderItem = GetFolderItem(outputFolder.Child(Tile).ShellPath, FolderItem.PathTypeShell)

Well, for Mac, you can use createSymbolicLink, linkItem and destinationOfSymbolicLinkAtPath functions in NSFileManagerMBS class in our plugins.

We also have folderitem.MacIsHardLinkedMBS as boolean function.

And for Windows, check the WindowsJunctionMBS class.

Sorry, i did not know this.

I have to test a path if it is a normal file/folder or a symbolic link.
I don’t get how to create a NSFileManagerMBS of a FolderItem.
Are there examples of it?

NSFileManagerMBS class has methods which take either path as string or folder item.

yes I can see that :slight_smile: aber was ist das Gute?

This isn’t working for Symbolic Links made by ln -s

And name includes Hard which says so.

[code]dim e as NSErrorMBS
dim path as string = NSFileManagerMBS.destinationOfSymbolicLinkAtPath("/tmp", e)

if path <> “” then
MsgBox path
end if
if e <> nil then
MsgBox e.LocalizedDescription
end if[/code]

okay?

Yes I found that too!

j=f.Count for i=1 to j ff = f.Item(i) dim e as NSErrorMBS dim path as string = NSFileManagerMBS.destinationOfSymbolicLinkAtPath(ff.UnixpathMBS, e) if path<>"" then TextArea1.Text=TextArea1.Text+Chr(13)+path end if next

Only when the destination couldn’t be found the string ‘path’ has a value!

You can check a FolderItem’s MacType value - it’s “slnk” for symlinks but not for regular Alias and bookmark files.

Like in this code:

dim type as String if f.Alias then if f.MacType = "slnk" then type = "Symlink" else type = "Alias" end if else type = "Regular" end if

Note, however, that you cannot receive dropped Symlinks - they get auto-resolved. However, dropping Alias files works, that’s why you should always resolve dropped files before handling them, or you’ll handle the Alias file instead. To resolve an Alias, use this code:

if f.Alias and f.Parent <> nil then f = f.Parent.Child(f.Name)

Also, you cannot have a user select Alias nor Symlink files with GetOpenFolderItem nor OpenDialog. I don’t know of a way to let the user select a Symlink file with Xojo.

And if you have the POSIX path of a file, you can use this code on Mac and Linux to check if it’s a symlink:

[code]Protected Function IsSymlink(path as String) As Boolean
dim stat_data as stat_t
if lstat (path, stat_data) = 0 then
return (stat_data.mode AND S_IFMT) = S_IFLNK
end
End Function

Protected Function lstat(path as String, ByRef dataOut as stat_t) As Integer
// lstat does not follow symlinks
#if TargetMacOS
declare function lstat lib “System” (path as CString, ByRef dataOut as stat_t) as Integer
return lstat (path, dataOut)
#endif
End Function

const S_IFMT = &hF000
const S_IFLNK = &hA000

structure stat_t
dev as UInt32
ino as UInt32
mode as UInt16
nlink as UInt16
uid as UInt32
gid as UInt32
rdev as UInt32
atime as UInt32
atimesec as UInt32
mtime as UInt32
mtimesec as UInt32
ctime as UInt32
ctimesec as UInt32
fsize as UInt64
blocks as UInt64
blksize as UInt32
flags as UInt32
gen as UInt32
lspare as UInt32
qspare1 as UInt64
qspare2 as UInt64
end[/code]

[quote=398660:@Thomas Tempelmann]And if you have the POSIX path of a file, you can use this code on Mac and Linux to check if it’s a symlink:
][/quote]
that won’t work for 64bit will it?

It should if you set the correct alignment (via an Attribute) for the struct (which would be 8 for 64 bit and 1 for 32 bit if I remember correctly). Or, it might be that the alignment needs to be set to 0 for both build types. Try for yourself.