MATLAB: How to rename images in a folder

images nametimestamp

Hello all,
I have several images named as:
Basler piA1000-60gm (22085941)_20190522_213447520_0001.bmp
Basler piA1000-60gm (22085941)_20190522_213447520_0002.bmp
I'd like to rename the images and keep the timestamp as:
20190522_213447520_0001.bmp
20190522_213447520_0002.bmp
or, if it is possible, I'd prefer rename the images with the timestamp when the images were created, for example using this format: 2019-05-22-21-34-47.520.
Thank you.

Best Answer

Ronny - let's assume that you have a list of file names (with or without a full path to the file). We can use strrep and movefile to replace the file name (remove the "prefix") and move the file respectively. For example,
for k = 1:length(myFilesToMove)
fromFilename = myFilesToMove{k};
toFilename = strrep(fromFilename, 'Basler piA1000-60gm (22085941)_', '');
movefile(fromFilename, toFilename);
end
where myFilesToMove is a cell array of your different files that you want to rename.