フィルターのクリア

Obtaining types of files in directory and put them into an array

3 ビュー (過去 30 日間)
Jason
Jason 2014 年 12 月 10 日
編集済み: Azzi Abdelmalek 2014 年 12 月 10 日
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

採用された回答

Orion
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
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

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by