필터 지우기
필터 지우기

Searching for a directory in matlab Path

조회 수: 27 (최근 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 CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by