输入为目录,输出为cell数组。使用第i个文件时,文件名为files{i}。
function [ files ] = scanDir( root_dir )
files={};
if root_dir(end)~='/'
root_dir=[root_dir,'/'];
end
fileList=dir(root_dir); %扩展名
n=length(fileList);
cntpic=0;
for i=1:n
if strcmp(fileList(i).name,'.')==1||strcmp(fileList(i).name,'..')==1
continue;
else
fileList(i).name
if ~fileList(i).isdir
full_name=[root_dir,fileList(i).name];
% [pathstr,name,ext,versn]=fileparts(full_name);
% if strcmp(ext,'.jpg')
cntpic=cntpic+1;
files(cntpic)={full_name};
% end
else
files=[files,scanDir([root_dir,fileList(i).name])];
end
end
end
end