Rename all image files (e.g. jpg) in a folder according to the file modification date
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joseba Moreno
am 12 Feb. 2020
Kommentiert: Joseba Moreno
am 17 Feb. 2020
Dear all,
I have been looking for a solution which helps me renaming all the JPG files I have on a folder according to their file modification date. However, any of the solutions I came with worked out for me... At the end, I would like that all the files in my folder have the following format: 20200212_1000, for instance...
Thank you very much in advance for your help.
Kind regards,
Joseba
0 Kommentare
Akzeptierte Antwort
Bhaskar R
am 12 Feb. 2020
Bearbeitet: Bhaskar R
am 12 Feb. 2020
Get the all jpg files
d = dir([path, '\*.jpg']);
Apply loop for each image file of the directory and get the filename
filename = fullfile(d(loop_var).folder,d(loop_var).name);
Get the image modified date and rename using reguler expression
filedetails = imfinfo(filename);
file_time_stamp = regexprep(filedetails.FileModDate, {'[-:]',' '}, {'', '_'});
renamed_filename = [file_time_stamp, '.jpg'];
renamed_filename = fullfile(d(loop_var).folder, renamed_filename);
Then move(rename) the file with modified name as
movefile(filename, renamed_filename);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!