Renaming files in a folder in bulk

Hi. I am trying to rename a bunch of MAT files within a folder.
For example, the current files are named: AB007_group2_subject011_naive_day2_rawdata.mat
Each file varies on the numbers after "subject", "group, and "day".
I would like to change all of the files to be in the following format: AB007_subject011_day2_rawdata.mat
So essentially, I just want to delete the group and naive portion of the filename.
Thanks a lot!

 Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 22 de Jul. de 2020
Editada: Fangjun Jiang el 22 de Jul. de 2020

0 votos

>> name='AB007_group2_subject011_naive_day2_rawdata.mat'
name =
'AB007_group2_subject011_naive_day2_rawdata.mat'
>> name=regexprep(name,'_group\d+','')
name =
'AB007_subject011_naive_day2_rawdata.mat'
>> name=regexprep(name,'_naive','')
name =
'AB007_subject011_day2_rawdata.mat'

3 comentarios

BobbyRoberts
BobbyRoberts el 22 de Jul. de 2020
Thanks, but this doesn't solve my problem. I suppose where I needed help was inserting that new name as the new filename for the current MAT already in the folder.
Fangjun Jiang
Fangjun Jiang el 22 de Jul. de 2020
movefile(OldFileName,NewFileName)
BobbyRoberts
BobbyRoberts el 22 de Jul. de 2020
That's it! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Jul. de 2020

Comentada:

el 22 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by