Obtaining types of files in directory and put them into an array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jason
el 10 de Dic. de 2014
Editada: Azzi Abdelmalek
el 10 de Dic. de 2014
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 comentarios
Respuesta aceptada
Orion
el 10 de Dic. de 2014
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.
Más respuestas (1)
Azzi Abdelmalek
el 10 de Dic. de 2014
Editada: Azzi Abdelmalek
el 10 de Dic. de 2014
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 comentarios
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!