1

MATLAB has a built-in predicate function, isdir, that takes as string as its argument, and returns true iff this argument represents the path to a directory.

I'm looking for a similar predicate, taking the same type of argument, but returning true iff this argument represents the path to a (Unix) symbolic link. (This returned value should be true for any symlink, irrespective of what type of file its target is, or whether this target exists at all.)

If MATLAB has no such predicate, then I'd like to know how best to implement it.

kjo
  • 33,683
  • 52
  • 148
  • 265
  • 3
    I'm not sure MATLAB can natively and I don't have a linux install to test, perhaps you can do something with the return of [`system`](http://www.mathworks.com/help/matlab/ref/system.html) or [`unix`](http://www.mathworks.com/help/matlab/ref/unix.html) and `ls -F searchquery` (the `-F` flag should append `@` to the end of symlinks)? – sco1 Sep 10 '15 at 13:53
  • 2
    Matlab has a [bridge to java](http://www.mathworks.com/help/matlab/matlab_external/bringing-java-classes-and-methods-into-matlab-workspace.html?refresh=true), use the methods [available in java](http://stackoverflow.com/questions/2490351/detecting-a-symlink-in-java) – Daniel Sep 10 '15 at 15:35

2 Answers2

1
unix('test -L slowlink.m')

Returns 1 if the file either does not exist or is not a link, 0 if it is a link (backwards, I know).

beaker
  • 16,331
  • 3
  • 32
  • 49
0

Did not test this since don't have matlab on this machine, BUT, let;s say your path string is in 'path_string' variable, then:

function a_winrar_is_you = issymlink(path_string)

[status, out] = unix(strcat('file ',path_string));
if ~isempty(strfind(out,'symbolic'))
    a_winrar_is_you = true;
else
    a_winrar_is_you = false;
end

end

Note that this is buggy, namely you'll have to check the exit status of file command, and it will give false positives on paths that contain 'symbolic', but I leave it up to someone less lazy than me (you) to polish it.

Hennadii Madan
  • 1,573
  • 1
  • 14
  • 30