getting all specific file names in path?

3 vues (au cours des 30 derniers jours)
Vivek
Vivek le 26 Fév 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?

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Fév 2013

Plus de réponses (1)

Morteza
Morteza le 26 Fév 2013
Modifié(e) : Morteza le 26 Fév 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)
%=====================================================================
  1 commentaire
Vivek
Vivek le 27 Fév 2013
Thank u morteza.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by