MATLAB: How to open the files in a directory

file

Hello,
I wrote a code that browse a directory and open it files one by one. Here is the code:
list= dir('rep/*');
for j=3:length(list)
f1= fopen(list(j).name,'r');
....
The problem is that the files can't be opened. If someone could help i will be thankful.

Best Answer

projectdir = 'rep';
dinfo = dir(fullfile(projectdir));
dinfo([dinfo.isdir]) = []; %get rid of all directories including . and ..
nfiles = length(dinfo);
for j = 1 : numfiles
filename = fullfile(projectdir, dinfo(j).name);
f1 = fopen(filename, 'r');
...
fclose(f1);
end