5
$\begingroup$

In this question we learn that we can use FindFile to get the disk location of a package. However, I have some packages that are installed into my $USER/Library/Mathematica/Applications/$ directory by symbolic link.

I'd like to be able to resolve the "true" path of these packages, much like the GNU readlink utility does. Does Mathematica have such a function built in? If not, by what other [preferably cross-platform] methods can this be accomplished?

$\endgroup$

2 Answers 2

9
$\begingroup$

AbsoluteFileName will resolve symbolic links.

Example on my machine:

AbsoluteFileName["/Library/TeX/texbin"]
(* "/usr/local/texlive/2019/bin/x86_64-darwin" *)
$\endgroup$
7
$\begingroup$

After a bit more fiddling around I found FileInformation, an undocumented function which takes a file name as an argument.

FileInformation[FindFile["myPackage"]]` returns

{AbsoluteFileName->/absolute/path/to/myPackage.wl,
 BlockCount->24,
 BlockSize->4096,
 ByteCount->8474,
 CreationDate->Thu 17 Oct 2019 11:06:04GMT-4.,
 Device->16777220,
 DirectoryName->$HOME/Library/Mathematica/Applications,
 FileAttributes->Missing[NotAvailable],
 FileBaseName->myPackage,FileExtension->wl,
 FileName->$HOME/Library/Mathematica/Applications/myPackage.wl,
 FileType->File,
 GID->20,
 GroupName->Missing[NotAvailable],
 Inode->28731823,
 LastAccessDate->Wed 23 Oct 2019 18:16:13GMT-4.,
 LastModificationDate->Wed 23 Oct 2019 18:16:10GMT-4.,
 LinkCount->1,
 OwnerName->Missing[NotAvailable],
 RawByteCount->12288,
 SetGroupID->False,
 SetUserID->False,
 Sticky->False,
 UID->501,
 UnixPermissionsCode->0660,
 UnixPermissionsString->-rw-rw----}

where I replaced my home directory with $HOME and the true readlink path with /absolute/path/to/myPackage.wl for privacy. CreationDate, LastAccessDate, and LastModificationDate are DateObjects, all the left-hand sides of the rules are "strings", and the right-hand sides are integers, strings, etc.

SO, what I was looking for was "AbsoluteFileName"/.FileInformation[FindFile["myPackage"]]`

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.