您的位置:首页 > 编程语言 > MATLAB

matlab遍历文件夹下的所有文件

2015-05-26 10:46 736 查看
输入为目录,输出为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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: