循环浏览文件夹? [英] Loop over folders?
本文介绍了循环浏览文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的代码:
myFolder='C:\Users\abe7rt\Desktop\dat\1';
filePattern=fullfile(myFolder, '*.txt');
txtFiles=dir(filePattern);
现在,dat是一个包含"1,2,3"个文件夹的文件夹,并且这些文件夹中的每个文件夹都包含20个TXT文件. 先前的代码能够从1个文件夹中获取txt文件.现在我的问题是:有没有办法遍历所有目录?
Now, dat is a folder that contains "1,2,3" folders and each one of these folders contains 20 TXT files. The previous code is able to get the txt files from 1 folder. Now my question is: is there a way to loop over all the directories?
推荐答案
是的:)
这是一个非常不错的功能:
A very nice function is this one:
您可以像这样使用它:
fileList = getAllFiles('D:\dic');
然后,您只需摆脱非txt文件,例如通过在循环中检查扩展名!
Then you just have to get rid of non-txt-files, e.g. by checking the extension within a loop!
这篇关于循环浏览文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文