使用fullfile函数:
% 根目录:
rootPath='C:\WorkSpace\shixun\code\cattle_face_data';
% fullfile函数获取文件夹list
folderList=dir(fullfile(rootPath));
% 文件夹下的文件个数,包含.和..,所以-2
fileNum=size(folderList,1)-2;
% 遍历所有文件夹名称
for k=3:fileNum
folderList(k).name % 这就是文件名,如果有子文件夹,则也包含在里面。
end