Rename TIF files in a folder
Mostra commenti meno recenti
Hi. I have 21841 TIF format files (in a folder) with names like: Camera_6_100fps_20240403_0956560001, and so to Camera_6_100fps_20240403_09565621841. I want to rename them to the format Camera60001 so on to Camera621841. I have tried a for loop but did not succeed. Can someone please help me with this.
Thanks.
2 Commenti
Michael VanMeter
il 4 Giu 2024
Can you post the for loop that you tried?
Tomer
il 4 Giu 2024
Risposta accettata
Più risposte (1)
Michael VanMeter
il 4 Giu 2024
You haven't provided enough detail on how you're attempting to rename these files, but a simple for loop using movefile should be sufficient. You can modify the dest (destination) variable as needed to get the desired naming convention.
files = dir('Camera_6*.tif');
[~, I] = sort([files.datenum]);
files = files(I);
fileNum = 60001;
for file = files'
src = fullfile(file.folder,file.name);
dest = fullfile(file.folder,['Camera',num2str(fileNum),'.tif']);
movefile(src, dest)
fileNum = fileNum + 1;
end
2 Commenti
Michael VanMeter
il 4 Giu 2024
Slightly different approach using regular expression.
files = dir('*.tif');
exp = 'Camera_\d+_\d+fps_\d+_\d{5}(\d+)\.tif';
for file = files'
matches = regexp(file.name,exp,'tokens','once');
dest = ['Camera',matches{1},'.tif'];
movefile(file.name, dest)
end
Tomer
il 5 Giu 2024
Categorie
Scopri di più su Hamamatsu Hardware in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!