我需要遍历一个文件夹(称为Data),其中包含许多具有不同名称的文件夹。我需要挑选一些特定的文件夹,每个文件夹都以相同的单词(Variance)开头。然后,当在这些“方差”中...文件夹有两个文件,我需要打开它们,并通过一个函数来获取一些信息。每个文件夹(F_1和F_0)的文件具有相同的名称:
1)遍历文件夹,直到找到名称以特定开头的子文件夹。
2)输入sub_folder
3)打开其中的两个文件,并将它们用于一个函数(我可以做到这一点)
4)返回到原来的文件夹(Data),循环查找特定子文件夹,重复直到找到所有子文件夹。
发布于 2015-08-14 01:59:17
是像这样吗?(为了我自己的目的进行了测试和运行,所以我知道它可以在评论行中描述的程度上工作)
function status = rview(thedir)
yesdirs = rdir(thedir,'isdir');
% when numel(yesdirs) ==0 there are no directories; note that yesdirs does
% not include . or .. by design.
if numel(yesdirs),
%assume no idiot every mixed files and directories in a given dir
for j =1:numel(yesdirs),
disp(sprintf('going to %s',yesdirs(j).name));
eval(sprintf('cd ''%s'' ', yesdirs(j).name));
thedir = sprintf('d%d',j);
stat(j).(thedir) = rview('.');
cd('..');
end
else
%no subdirectories.. worked our way to the bottom
your_function_here()
% indicator of where we were
stat= ['did_' cd];
end
status = stat;
endhttps://stackoverflow.com/questions/31994553
复制相似问题