Obtaining types of files in directory and put them into an array
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a range of files in a directory that I am loading into a listbox component in a GUI. In an attempt to sort firstly by extension, it has been suggested that I stack the types of files. In order to do this, I need to know what types of files exist. I am trying to get an array which just consists of all the different types of file extensions:
first i initialise the array to hold the types of files
extlist=[]; % Initialise the array
I then loop thru all files and use file parts to pull out the extension:
[folder1, name, extension] = fileparts(baseFileName);
I then attempt to add this to the array
extlist=vertcat(extlist,extension)
and this is where my attempt fails. I also do not know how to pick out single occurances so my array will just contain what types of files are present. With this list I want to then perform a stack listing procedure.
thanks for any pointers. Jason
댓글 수: 0
채택된 답변
Orion
2014년 12월 10일
you're trying to concatenate strings of different lengths, it can't work.
put them in a cell array.
files = dir;
AllExtension = [];
for i = 3:length(files)
[pathstr,name,ext] = fileparts(files(i).name);
AllExtension{end+1,1} = ext;
end
AllExtension = unique(AllExtension); % get only one time the different extensions.
추가 답변 (1개)
Azzi Abdelmalek
2014년 12월 10일
편집: Azzi Abdelmalek
2014년 12월 10일
s=dir,
f={s.name} % The list of your files
a=regexp(f,'(?<=\.)[^\.]+$','match')
b=a(~cellfun(@isempty,a)) % list of non empty extensions
c=unique([b{:}]) % unique extension
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!