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!