Effacer les filtres
Effacer les filtres

How to rename files in subfolders within a folder

1 vue (au cours des 30 derniers jours)
Deep
Deep le 19 Oct 2018
Modifié(e) : Deep le 22 Oct 2018
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 commentaires
Stephen23
Stephen23 le 20 Oct 2018
Modifié(e) : Stephen23 le 20 Oct 2018
Deep
Deep le 22 Oct 2018
Modifié(e) : Deep le 22 Oct 2018
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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by