MATLAB: Linux Matlab – is it possible to determine whether a directory is a link

linked directory

I wrote a simple Matlab script using "dir" to recursively follow directories in a linux environment. The only thing is I don't want to follow linked directories. Does Matlab have a way of figuring out which directories are linked directories? On my Linux window, linked dirs show up as
/dir_x -> /home/some_directory_path/some_other_path/
rather than just /dir_x

Best Answer

Try somthing like
[a,b]=system('ls -l /tmp/myfile | cut -c 1')
if b is an 'l' (ell), then /tmp/myfile is a link, if it's a 'd' then it's a regular directory. There are some other special types like 's','p','b','c' but most common are 'd' and 'l'.
Another way can be
[a,b]=system('stat -c ''%F'' /tmp/DELETEME')
If 'b' says 'symbolic link' there you got it, if it says 'directory', it is a directory.
Just another tip. Beware of newlines that may be at the end of b. I usually get rid of them piping the output through an
tr -d '[\r\n]'
at the end of the command. strtrim function is also handy. Regards!