rename files in a folder

조회 수: 89 (최근 30일)
Franziska Motka
Franziska Motka 2023년 2월 22일
댓글: Franziska Motka 2023년 2월 24일
Hi everyone,
I have a folder with hundreds of files in it, named like CBM32002.MR.STUDIES_PSYCHOLOGY.0001.0001.2023.02.07.18.44.40.94243.158444734. CBM320 is the participants ID. I accidently named this particants wrong, it would be CBM330 instead of CBM320. Could somebody help me to write a code which is renaming all files in the folder from CBM320... to CBM330... ?
Thanks for any help!
Best,
Franziska
  댓글 수: 2
Stephen23
Stephen23 2023년 2월 22일
What is the file extension of the files?
Franziska Motka
Franziska Motka 2023년 2월 22일
they are all IMA files, so e.g. CBM32002.MR.STUDIES_PSYCHOLOGY.0001.0001.2023.02.07.18.44.40.94243.158444734.IMA

댓글을 달려면 로그인하십시오.

채택된 답변

Akira Agata
Akira Agata 2023년 2월 22일
How about the following solution?
% Create list of all files in the current folder
s = dir(pwd);
s = struct2table(s);
% Extract the files with the file name of CBM320~
idx = startsWith(s.name, 'CBM320');
s = s(idx,:);
% Create current file names and new file names
oldFileName = s.name;
newFileName = replace(oldFileName, 'CBM320', 'CBM330');
% Change the file name one-by-one
for kk = 1:numel(oldFileName)
movefile(oldFileName{kk}, newFileName{kk});
end
  댓글 수: 1
Franziska Motka
Franziska Motka 2023년 2월 24일
Finally, I was able to try the code on my PC. It worked! Thank you very much for your help :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by