Searching for a directory in matlab Path

65 views (last 30 days)
Deepak
Deepak on 22 Aug 2011
Answered: Subhadra Mahanti on 4 Feb 2016
Hi, I want to find out if a particular directory name exists in the matlab path. This I can do easily with exist('dirname','dir') If the directory now exists, then I wish to find its complete path from the Matlab PathList. Could someone help me out with this.
Thanks.

Answers (2)

Fangjun Jiang
Fangjun Jiang on 22 Aug 2011
I don't fully understand how exist('dirname','dir') works. If you need to find out the full path, I recommend the following code which tries to find the folder 'simulink'.
use regexpi() to replace strfind() if want to ignore the case, but then also need to take care of the backlash '\'. Maybe should just use
Ind=strfind(lower(PathStr),lower([filesep,'dirname']))
PathStr=regexp(path,pathsep,'split');
Ind=strfind(PathStr,[filesep,'simulink']);
Ind=cellfun('isempty',Ind);
FoundPath=PathStr(~Ind)

Subhadra Mahanti
Subhadra Mahanti on 4 Feb 2016
If exist(myDir,'dir')==7 I usually go to the MATLAB root and do a system find, but remember this can return several values based on all the directories with the name myDir on the path
cd(matlabroot)
!find . -name myDir
Another way to run system commands in MATLAB is
[status,cmdout] = system(cmd,'echo') % where cmd='find . -name myDir &'

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!