필터 지우기
필터 지우기

How can I create a list of files of the defined typ that are included in the folder?

조회 수: 2 (최근 30일)
Hello,
I should use this code (see below) to create a list o files of the defined typ that are included in the folder. Unfortunately, I get an error. It is saying that my pathname is too long. What can I do?
function fileList= createFileList(typ, folder)
fileCount =0;
listofFiles={};
folders=genpath(folder);
folders=regexp([folders ';'],'(.*?);','tokens');
for pathNr=1:size(folders,2)
folder=cell2mat(folders{pathNr});
if ~isempty(folder)
files=dir(fullfile(folder,strcat('*.',typ)));
if ~isempty(files)
for fileNr=1:size(files,1)
fileCount=fileCount+1;
file=strcat(folder,'\',files(fileNr).name);
listofFiles{fileCount,1}=file;
end
end
end
end
fileList=listofFiles;
end

채택된 답변

Stephen23
Stephen23 2021년 1월 3일
편집: Stephen23 2021년 1월 3일
folder = '...';
typ = 'm';
T = sprintf('*.%s',typ);
G = genpath(folder);
F = regexp(G,'[^:]+','match');
C = cell(size(F));
for k = 1:numel(F)
C{k} = dir(fullfile(F{k},T));
end
S = vertcat(C{:});
L = fullfile({S.folder},{S.name})

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by