Load files in a loop
显示 更早的评论
Hi, I didn't see an answer to this question anyway, and it's very possible I missed it. But I was wondering if anyone could help me load files in several folders in a loop.
The situation I have is folder A with folders AA,BB,CC within. AA contains A1,A2,A3, BB contains B1,B2,B3 and CC contains C1,C2,C3. But withint AA,BB,CC I only want the 15 files contained in the second folder.
I tried this:
cd('C:\A');
fault = dir(cd)
for i=3:length(fault); data=dir(fault(i));
for ii=3:length(data);
data2=dir(data(ii));
end
end
But that clearly didn't work.
Any suggestions?
回答(1 个)
Image Analyst
2015-4-6
0 个投票
Check out the attached demo where I get all subfolders of a folder and go into all the folders getting the names of all the files in each folder. I use genpath() and dir(). Feel free to adapt the file patterns you pass to dir() as needed for your situation.
类别
在 帮助中心 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!