how to extract information from subfolders

조회 수: 3 (최근 30일)
andrew
andrew 2014년 3월 28일
답변: Image Analyst 2014년 3월 28일
I was able to produce the following code that is able to get the folders within a specific folder:
files = dir(C:\Users\abcde\Documents\MATLAB);
directoryNames = {files([files.isdir]).name};
directoryNames = directoryNames(~ismember(directoryNames,{'.','..'}))';
however I am trying to get the csv files within each subfolder called "object statistics" from each of the folders I pulled out from the code above. I have the following code:
for i=1:length(directoryNames)
folder=directoryNames{i};
filenames=ls([folder '\results\object statistics *.v2*'])
end
It is not doing what I want; trying to loop through each folder's subfolder called object statistics and pull out the csv file. how do I do this?
  댓글 수: 1
Joseph Cheng
Joseph Cheng 2014년 3월 28일
I've only been able to do it manually by writing loops to go and search in subfolders contained in the main folder and add to a master list of folder and filenames. Which gets messy when subfolders contain subfolders.
Commenting to "bookmark" so if someone has a good answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2014년 3월 28일
See my attached script (below in blue text) to recurse into subfolders, getting file names. A simple adaptation will get you what you want.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by