How to name files in a folder based on parent folder?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello all,
I'm newbie to Matlab and I got a question regarding naming files in folders. I have 6 folders let's say simulation_data1 to 6, and there are 17 pictures in each folders which are named block_1 to 17 now in all 6 folders. I was wondering how can I name each batch of pictures (17 figs) in every folder based on the name of parent folder? For example, all figs in folder simulation_data1 become simulation_data1_1 to 17.
any help would be appreciated.
regards
댓글 수: 0
채택된 답변
Chunru
2022년 5월 9일
for i=1:6 % 6 folders
foldername = sprintf('simulation_data%d', i)
mkdir(foldername)
cd(foldername)
for j=1:2 % 2 files for example
filename = sprintf('%s_%d', foldername, j);
fprintf(' Filename: %s\n', filename)
save(filename, 'filename'); % create a file
end
cd( '..');
end
dir
댓글 수: 5
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!