Change Folder Name without complete name of the fFolder
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2020-1-28
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.
回答(1 个)
Image Analyst
2020-1-28
Try indexing:
newFolderName = currentFolderName(1:end-3); % Chop off last 3 characters.
movefile(currentFolderName, newFolderName); % Rename folder.
2 个评论
Image Analyst
2020-1-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!