How to rename files in subfolders within a folder

조회 수: 6 (최근 30일)
Deep
Deep 2018년 10월 19일
편집: Deep 2018년 10월 22일
I have multiple files in subfolders within a main folder. I want to rename the files by inserting some text before the actual file name.
For example I have subfolders with different names 32_post, 43, 44 etc. and each subfolder has different files smooth_frame0.nii.gz, moved_frame.nii.gz and I want to rename these files as P32_post_smooth_frame0.nii.gz, and so on...
  댓글 수: 2
Stephen23
Stephen23 2018년 10월 20일
편집: Stephen23 2018년 10월 20일
Deep
Deep 2018년 10월 22일
편집: Deep 2018년 10월 22일
Thanks for your help. However, I have a follow up question. I have the old file name (eg. smooth_frame0.nii.gz) and I have the folder name as a string (eg. 12_post). How do I create a new file name 12_post_smooth_frame0.nii.gz ?
D = dir;
D = D(~ismember({D.name}, {'.', '..'}));
for k = 1:length(D)
currD = D(k).name;
fList = dir(currD); % Get the file list in the subdirectory
fList = fList(~ismember({fList.name}, {'.', '..'}));
oldFileName = fList(k).name;
newFileName = ???????
movefile(oldFileName, newFileName);
end

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

답변 (0개)

카테고리

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