Azzera filtri
Azzera filtri

How to have Matlab respect/remember symbolic links in path?

15 visualizzazioni (ultimi 30 giorni)
Hi,
I'm working on a piece of code that will be used by many people on different machines, and so I'm using relative directory paths to define the location of several necessary source files (i.e. hard coding directory paths will not work).
I am working on an OSX machine as well.
Lets say I have files in two main locations
/Volumes/WorkingDir/BaseDir (BASEDIR)
and
/Volumes/WorkingDir/ExtraFilesDir
The problem I'm finding is that if the folder BaseDir is actually a symbolic link (not an alias) to another folder located in
BaseDir -> /Volumes/OtherDir
then when I make a call to:
/Volumes/WorkingDir/BaseDir/../ExtraFilesDir
Matlab reports that it cannot find "ExtraFilesDir" because it actually is looking for the folder in
/Volumes
When I want it to be looking in
/Volumes/WorkingDir
The OSX Terminal does not have this problem, it respects and holds symbolic links in the working directory, whereas it seems Matlab does not. Does anyone know a way to have Matlab respect Symbolic Links? I.e. have
BASEDIR/../ equal to /Volumes/WorkingDir
I realize I could set the "WorkingDir" as the base directory and it would work too, but there is a compatibility issue that exists there (just trust me on that one, it could be done, but would be a hassle)
Summary: In essence, I can get matlab to correctly follow symbolic links but not properly back out of a symbolic link, and I would like to know if this is possible.
Thanks!
  4 Commenti
Alexander
Alexander il 17 Ott 2011
where the "/.." at the end denotes "go up one level in the directory".
"cd .." well move from "/A/B" to "/A" for example
Daniel Shub
Daniel Shub il 17 Ott 2011
I understand now. It appears that MATLAB only handles links physically and not logically. The problem is not /.., but rather the following of the symbolic link. For me
cd /Volumes/WorkingDir/BaseDir
pwd
returns
/Volumes/OtherDir
where /Volumes/WorkingDir/BaseDir -> /Volumes/OtherDir
I wonder if Jan's getfullpath would help
http://www.mathworks.com/matlabcentral/fileexchange/28249-getfullpath

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 19 Ott 2011
I thought the behavior you noted is a bug, so I went looking for reference material to support your opinion. Instead I ended up finding support for the form used by MATLAB.
The appropriate POSIX routine to determine the current working directory is getcwd(), the official POSIX description of which starts,
The getcwd() function shall place an absolute pathname of the current working directory in the array pointed to by buf, and return buf. The pathname copied to the array shall contain no components that are symbolic links.
I not know why POSIX choose that behavior, but one cannot fault Mathworks with going with standard system calls rather than working through the paths step by step to figure out where one is in the symbolic tree.

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by