Reputation: 35311
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.
Upvotes: 1
Views: 954
Reputation: 16791
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).
Upvotes: 1
Reputation: 1623
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.
Upvotes: 0