Searching for a directory in matlab Path

65 ビュー (過去 30 日間)
Deepak
Deepak 2011 年 8 月 22 日
回答済み: Subhadra Mahanti 2016 年 2 月 4 日
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.

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 22 日
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 2016 年 2 月 4 日
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 &'

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by