how to get the specific model name/ extention(.mdl) from a folder which has count less depths?

조회 수: 3 (최근 30일)
i would like to extract the *.sldd and *.h files from the folder which has multiple levels. example: folder X has X1,X2folders, X1 has Y1, Y2 and Y3 folders and Y2 has Z1,Z2 folders. Z2 folder contains some test.h file and Z1 contains some data.sldd
is there API to sort out the required file names based on extention?

채택된 답변

Jordan Ross
Jordan Ross 2016년 9월 21일
Hi Sudhakar,
In MATLAB R2016b you can use the "dir" function as follows:
>> list = [dir('**/*.sldd'); dir('**/*.h')]
The variable "list" will then contain a vector of structures which correspond to the files with the extensions .SLDD and .H.
For more information about the "dir" function see: http://www.mathworks.com/help/matlab/ref/dir.html
  댓글 수: 1
Sudhakar Akki
Sudhakar Akki 2016년 9월 22일
Thanks for answer. currently i'm using R2014a. for sorting out the *.sldd files i made a script.
function [ FList_sldd ] = ReadDDNames(DataFolder) DirContents=dir(DataFolder); FList_sldd=[];
if(strcmpi(computer,'PCWIN') strcmpi(computer,'PCWIN64')) NameSeperator='\'; elseif(strcmpi(computer,'GLNX86') strcmpi(computer,'GLNXA86')) NameSeperator='/'; end
extList={'.sldd'}; for i=1:numel(DirContents) if(~(strcmpi(DirContents(i).name,'.') strcmpi(DirContents(i).name,'..'))) if(~DirContents(i).isdir) extension=DirContents(i).name(end-4:end); if(numel(find(strcmpi(extension,extList)))~=0) FList_sldd=cat(1,FList_sldd,{[DataFolder,NameSeperator,DirContents(i).name]}); end else getlist=ReadDDNames([DataFolder,NameSeperator,DirContents(i).name]); FList_sldd=cat(1,FList_sldd,getlist); end end end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by