getting all specific file names in path?

1 visualización (últimos 30 días)
Vivek
Vivek el 26 de Feb. de 2013
I add a folder in current path after using restoredefaultpath. In a folder(eg.AllModules). I am having many folders(eg.f1,f2...f25).
all my f1,f2....,f25 folder having four files naming abcf1.mdl, abcf1_ref.mdl, abcf1ML.mdl, abcf1TL.mdl. likewise in f2 folder abcf2.mdl, abcf2_ref.mdl, abcf2ML.mdl, abcf2TL.mdl.
So I need a script to get all the file of name abcf1.mdl,abcf2.mdl,.........abcf25.mdl in a variable. pls help on this?

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Feb. de 2013

Más respuestas (1)

Morteza
Morteza el 26 de Feb. de 2013
Editada: Morteza el 26 de Feb. de 2013
Try this:
But you have to enter the path in command line and in the '' like ==> ' YourPath '
%=====================================================================
clc,clear
Pathname = input('Enter Path : ');
addpath(genpath(Pathname));
%Find the information about path
Info = dir(Pathname);
%First two item does not have usefull information
count = 1;
for i = 1:size(Info)-2
if Info(i,1).isdir ~= 0
info{count,:} = struct2cell(dir([Pathname,'\',Info(i+2,1).name]));
count = count+1;
end
end
NumFold = size(info);
count = 1;
for i = 1:NumFold(1)
NumItem = size(info{i,1});
for j = 1:NumItem(2)
if (strcmp(info{i,1}{1,j},'.') ~= 1 && strcmp(info{i,1}{1,j},'..') ~= 1)
ItemNames{count,1} = info{i,1}{1,j};
count = count+1;
end
end
end
Your_Items_Name = cellstr(ItemNames)
%=====================================================================

Categorías

Más información sobre Entering Commands 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!

Translated by