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!