Change Folder Name without complete name of the fFolder
1 回表示 (過去 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!