getting all specific file names in path?

3 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2013-2-26

更多回答(1 个)

Morteza
Morteza 2013-2-26
编辑:Morteza 2013-2-26
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)
%=====================================================================

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by