How to rename files in subfolders within a folder

1 次查看(过去 30 天)
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 个评论
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