필터 지우기
필터 지우기

looping though multiple sub-directories

조회 수: 1 (최근 30일)
Ben
Ben 2019년 7월 18일
댓글: Rik 2019년 7월 19일
I would like to recursively proces files in subdirectories using MATLAB. I have three subject-specific subdirectories (sub_001, sub_002, sub_003) in a main directory, A, each of which contains a .nii file, B.
In linux, this is possible using a for loop with a .txt file containg a listing of the main directory. For example:
for i in `cat list.txt`; do mv /A/$i/B /path/to/new/destination; done
Can the same be acheived in MATLAB? Essentially, the only thing that needs to change in each iteration is the subject's directory.
Thank you,
Ben

답변 (2개)

Rik
Rik 2019년 7월 18일
Yes, you just need to load your text file with your paths, and then loop over the contents. If you need help with loading the text file, you can post an example.
  댓글 수: 2
Ben
Ben 2019년 7월 19일
I don't understand how to load the .txt file with the path. I can't find reference to this online.
Rik
Rik 2019년 7월 19일
Reading a file is not a difficult task in Matlab. If you Google it you're bound to find dozens of examples. If you use a function like my readfile FEX submission, then you can use the resulting cell array directly in a loop.
You can also directly read all nii files with the code Jan showed you.

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


Jan
Jan 2019년 7월 19일
FileList = dir('C:\Base\Folder\**\*.nii');
for k = 1:numel(FileList)
File = fullfile(FileList(k).folder, FileList(k).name);
...
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by