首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >循环浏览文件夹matlab

循环浏览文件夹matlab
EN

Stack Overflow用户
提问于 2015-08-14 01:12:54
回答 1查看 1.1K关注 0票数 1

我需要遍历一个文件夹(称为Data),其中包含许多具有不同名称的文件夹。我需要挑选一些特定的文件夹,每个文件夹都以相同的单词(Variance)开头。然后,当在这些“方差”中...文件夹有两个文件,我需要打开它们,并通过一个函数来获取一些信息。每个文件夹(F_1和F_0)的文件具有相同的名称:

1)遍历文件夹,直到找到名称以特定开头的子文件夹。

2)输入sub_folder

3)打开其中的两个文件,并将它们用于一个函数(我可以做到这一点)

4)返回到原来的文件夹(Data),循环查找特定子文件夹,重复直到找到所有子文件夹。

EN

回答 1

Stack Overflow用户

发布于 2015-08-14 01:59:17

是像这样吗?(为了我自己的目的进行了测试和运行,所以我知道它可以在评论行中描述的程度上工作)

代码语言:javascript
运行
复制
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;
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31994553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档