Change Folder Name without complete name of the fFolder

4 vues (au cours des 30 derniers jours)
Theophane Piette
Theophane Piette le 28 Jan 2020
Commenté : Image Analyst le 28 Jan 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 commentaire
Adam
Adam le 28 Jan 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.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 28 Jan 2020
Try indexing:
newFolderName = currentFolderName(1:end-3); % Chop off last 3 characters.
movefile(currentFolderName, newFolderName); % Rename folder.
  2 commentaires
Theophane Piette
Theophane Piette le 28 Jan 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 le 28 Jan 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type 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