MATLAB Answers

I need to locate an installed program in MacOS using Matlab, how can I do that?

1 view (last 30 days)
I need to locate an installed program in MacOS using Matlab, how can I do that?
My Matlab code needs to make sure a certain 3rd party program is installed on the computer running the matlab code.
I have a way to do it on Windows ('WHERE /F /R "C:\Users\...'), but how can I do it in Matlab?

  0 Comments

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 22 Aug 2019
Mårten - you could try something like
[status, path] = system('find ~/Documents/geoff -name myFile.m')
The above would search in all directories (and subdirectories) for a file named myFile.m. If the file can be found, then the path would be set with the location of that file.

  2 Comments

Walter Roberson
Walter Roberson on 22 Aug 2019
It can pay to first use system() of a 'which' command. which is a shell built in that looks on the Unix path.
In theory you could ask Spotlight about the file, but in my experience it is common for Spotlight to not find what I am looking for.
The unix find command can be slow, especially if you do not confine it to a single mount point (drive) and very slow if you somehow get it searching a Time machine volume.
Sometimes it is best to just try the most common locations like /bin and /usr/bin and /usr/local/bin and look in /opt where Homebrew tends to install, and look in the user's ~/Applications and similar, and look at environment variables for an appropriate name... And if it is not in those places then either prompt the user or force a configuration step be done. Looking through all the drives can take hours (I have more than 10TB these days.)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!