Selecting .tif files from a folder and copy them to another folder

13 vues (au cours des 30 derniers jours)
Ashfaq Ahmed
Ashfaq Ahmed le 10 Avr 2022
Commenté : Voss le 10 Avr 2022
Hi!
I have these 34 days folders and each folder contains 3 images (.tif) files. I want to select all these .tif files and copy them to another folder named "All_tif_images".
I wrote down this code but it is not working. Can anyone please tell me what's wrong with the code? Any feedback will be much appreciated!
clear all; close all; clc;
HOME = '/Users/aahmed78/PhD/Data/SWOT/Beaufort Gyre - CalVal/May2015';
day = [1:34];
foldername = 'All_tif_images';
for zz=1:size(day,2)
cd(strcat(HOME,'/Day ',num2str(day(zz))))
file_list = dir('*.tif');
filenumber = length(file_list);
for i = 1:filenumber
filename = file_list(i).name;
cd('..');
copyfile(filename,cd(strcat(HOME,'/All_tif_images')));
end
end

Réponse acceptée

Voss
Voss le 10 Avr 2022
clear all; close all; clc;
HOME = '/Users/aahmed78/PhD/Data/SWOT/May2015';
foldername = 'All_tif_images';
foldername = fullfile(HOME,foldername);
file_list = dir(fullfile(HOME,'Day*','*.tif'));
for ii = 1:numel(file_list)
filename = fullfile(file_list(ii).folder,file_list(ii).name);
copyfile(filename,foldername);
end
  2 commentaires
Ashfaq Ahmed
Ashfaq Ahmed le 10 Avr 2022
Works perfectly! Thanks so much!
Voss
Voss le 10 Avr 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by