Borrar filtros
Borrar filtros

Searching for a directory in matlab Path

27 visualizaciones (últimos 30 días)
Deepak
Deepak el 22 de Ag. de 2011
Respondida: Subhadra Mahanti el 4 de Feb. de 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.

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 22 de Ag. de 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 el 4 de Feb. de 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 &'

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by