getting all specific file names in path?

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 26 Feb 2013

Più risposte (1)

Morteza
Morteza il 26 Feb 2013
Modificato: Morteza il 26 Feb 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)
%=====================================================================

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by