rename files in a folder
122 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Franziska Motka
el 22 de Feb. de 2023
Comentada: Franziska Motka
el 24 de Feb. de 2023
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 comentarios
Respuesta aceptada
Akira Agata
el 22 de Feb. de 2023
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
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!