Borrar filtros
Borrar filtros

How to rename files in subfolders within a folder

1 visualización (últimos 30 días)
Deep
Deep el 19 de Oct. de 2018
Editada: Deep el 22 de Oct. de 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 comentarios
Stephen23
Stephen23 el 20 de Oct. de 2018
Editada: Stephen23 el 20 de Oct. de 2018
Deep
Deep el 22 de Oct. de 2018
Editada: Deep el 22 de Oct. de 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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by