輸入爲目錄,輸出爲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