Change Folder Name without complete name of the fFolder

4 visualizaciones (últimos 30 días)
Theophane Piette
Theophane Piette el 28 de En. de 2020
Comentada: Image Analyst el 28 de En. de 2020
Hi,
I'm using an old script to convert my Dicom Scan into Nifti, and this Script is creating several folders named:
Run1_12
Run2_15
Run3_18
....
And the 2 digit after the "Run1" are random
So i'm trying to create a code to change these name into Run1, Run2 ... I've tried to use the fonction "Movefile" but i don't know how to ask him to change the name of Run1_12 without giving him the randon digit.
If someone has an idea, that would really help me :D
  1 comentario
Adam
Adam el 28 de En. de 2020
Can't you just do simple string manipulation to remove everything after, and including, the _ to give your target filename? I guess you could either use regexp for that or a simple strfind on '_' and remove everything after that index.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 28 de En. de 2020
Try indexing:
newFolderName = currentFolderName(1:end-3); % Chop off last 3 characters.
movefile(currentFolderName, newFolderName); % Rename folder.
  2 comentarios
Theophane Piette
Theophane Piette el 28 de En. de 2020
I've tried with movefile, but it's just creating a ney folder name 'Run1' and put 'Run1_01' in it.
Image Analyst
Image Analyst el 28 de En. de 2020
Leave the semicolon off to see what newFolderName really is.
newFolderName = currentFolderName(1:end-3) % Chop off last 3 characters.
% Print out what it's going to do.
fprintf('Going to rename %s to %s.\n'. currentFolderName. newFolderName);
movefile(currentFolderName, newFolderName); % Rename folder.
d = dir(newFolderName)
fprintf('Made %s\n', d.name);
I see no reason why, if the folder name is really Run1 why movefile would add _01 to it when it's not in the destination folder name. Run the above code and tell me what you see in the command window.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by