Path with shortcut/link

23 views (last 30 days)
Jonas
Jonas on 4 Jul 2012
Does Matlab support shortcuts or symbolic links in paths. Example:
/lib_v1.1
/lib_v1.2
/current -> /lib_v1.2
The "current" is a shortcut to the latest version of the lib, but is displayed as current.lnk by the dir command
>> dir
. .. current.lnk lib_v1.1 lib_v1.2
It have no effect when adding the path
addpath(genpath('current'))
and will result in an error by cd
>> cd('current')
??? Error using ==> cd
Cannot CD to current (Name is nonexistent or not a directory).
>> cd('current.lnk')
??? Error using ==> cd
Cannot CD to current.lnk (Name is nonexistent or not a directory).
What are my options?
  1 Comment
Jan
Jan on 5 Jul 2012
Do you need this on a Windows, Linux or MacOS? And if it concerns Windows, could you obtain admin privilegs to create hard-links instead of the not working soft-links?

Sign in to comment.

Accepted Answer

Jan
Jan on 5 Jul 2012
Is there any need to create links on the file system? I assume a software solution would be better:
Contents of the base folder:
/lib_v1.1
/lib_v1.2
Program for initializing the path;
current = 'lib_v1.2';
addpath(genpath(current))
Or you could you store the information in a text file:
Contents of the base folder:
/lib_v1.1
/lib_v1.2
/current_lib.txt -> contents: "lib_v1.2"
Program:
Current = fileread('current.txt');
% Perhaps: Current = strtrim(Current);
addpath(genpath(Current))
  1 Comment
Jonas
Jonas on 5 Jul 2012
Thanks Jan for the answer.
Actually I just read you post yesterday regarding project versions and paths.
In the my final solution all the configurations are stored in ini files in the project directory. I have create a collection of matlab functions to read and retrieve entries in the ini files: iniread, iniget, iniany and inigetvpath. The iniany will search for a configuration file and use the first found, and inigetvpath will get the versioned path entry in the ini file. It will use the current version from current.txt if no version is specified in the config file.
Cheers, and thanks for the replies.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 4 Jul 2012
MS Windows does not have true links. The .lnk file you are seeing is processed by Windows Explorer rather than by MS Windows. In order for programs to take .lnk files in to account, the programs have to detect them and make a call to Windows Explorer to do the resolution on behalf of the program.
The situation is quite different in Linux and OS-X, both of which handle symbolic links automatically at the operating system level (and require that programs take extra actions if they want to distinguish symbolic links from regular files.)
  1 Comment
Jonas
Jonas on 5 Jul 2012
So the conclusion is that you can NOT use file paths in Matlab that contain a shortcut on a Windows PC?
Do you have any trick or alternative solution for my problem?

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!