Filter löschen
Filter löschen

getting all specific file names in path?

5 Ansichten (letzte 30 Tage)
Vivek
Vivek am 26 Feb. 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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Feb. 2013

Weitere Antworten (1)

Morteza
Morteza am 26 Feb. 2013
Bearbeitet: Morteza am 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)
%=====================================================================

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by