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!